一、安装mysql数据库
①下载并解压上传到/opt/soft目录(soft目录是自己创建的)

②解压:tar -xvf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar

③清空linux自带的数据库
1.查看是否有旧版本的数据库:
rpm -qa |grep mysql

rpm -qa | grep mariadb

2. 卸载已有的数据库:(卸载会把这个包的依赖包也一起卸载)
yum -y remove mariadb-libs.x86_64

④安装mysql社区版服务包:
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm

发现需要5个依赖包,所以先安装依赖包 (needed 依赖)
1.安装perl的依赖包:
yum -y install perl (此处安装了27个带perl的包,包含3个依赖包)
2.安装mysql-community-client的依赖包:
rpm -ivf mysql-community-client-5.7.27-1.el7.x86_64.rpm

发现这个包依赖于:mysql-community-libs,所以先安装mysql-community-libs包。
安装mysql-community-libs库包:
rpm -ivf mysql-community-libs-5.7.27-1.el7.x86_64.rpm

3.再安装mysql-community-cient-5.7.27-1.el7.x86_64.rpm

4.安装mysql-community-common的依赖包:
rpm -ivf mysql-community-common-5.7.27-1.el7.x86_64.rpm
⑤再次安装mysql社区版服务器包:
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm

⑥验证mysql是否安装成功(启动不报错说明安装成功)
启动mysql服务:systemctl start mysqld.service

二、找到临时密码并修改
①查找存放临时密码的文件:
find / -name mysql*log

②查看临时密码:
more /var/log/mysql.log | grep temp

(密码是C_XMoVU7jjcW)
③输入mysql -u root -p 以及临时密码登录,进入mysql数据库的环境

④在mysql数据库的环境下:
1.设置mysql密码策略:
mysql>set global validate_password_policy=0;
2. 设置mysql密码的长度:
mysql>set global validate_password_length=4;
3.设置密码:
mysql>set password=password('123456');

4.退出:quit; 或者ctrl+z
三、查看和创建远程连接用户
①查看用户是否能够远程连接:
1.登录:mysql -u root -p; 输入密码登录(123456)
 
2.进入:use mysql;

3.查看:select host,user,authentication_string from user;

②创建远程用户
1.创建用户:create user 'myroot'@'%' identified by '123456';

2.赋权限:grant all privileges on *.* to 'myroot'@'%';

3.刷新:flush privileges;

四、使用Navicat工具远程登录
①关闭防火墙:systemctl stop firewalld.service
②进行连接

③连接成功

五、配置java项目
项目包含:程序包(.war)+数据包(.sql)
①把 .war和程序包上传到tomcat下的wbapps目录(在/opt/soft/apach-tomcat-8.5.47目录下)

②把 .sql的数据包导入Navicat (连接之后,左击,再点击运行SQL 文件)

③启动tomcat服务: (要在apache-tomcat-8.5.47目录下的bin目录下启动)
sh startup.sh

④修改项目连接数据库的文件,让项目连接上数据库
默认路径:(项目上传后自动解压,先刷新一下)
/opt/sotp/apache-tomcat-8.5.47/webapps/test/WEB-INF/classes

修改:
1.数据库服务ip地址: (改成linux的ip地址)
2.数据库名称: (改成项目数据库名称)
3.远程连接用户的用户名: (用户名myroot)
4.远程连接用户的密码: (用户myroot的密码)
5.保存

⑥关闭防火墙:
systemctl stop firewalld.service
⑦打开网页:输入192.168.1.181:8080/test

⑧输入用户名、密码测试登录

⑨登录

以上就是本次介绍的linux安装mysql配置Java的全部知识点,感谢大家的学习和对社区的支持。 |