文章目录
- 一、检查是否安装过MySQL
- 二、上传安装包
- 三、安装MySQL
-
- [3.1 安装mysql依赖](#3.1 安装mysql依赖)
- [3.2 安装mysql-client](#3.2 安装mysql-client)
- [3.3 安装mysql-server](#3.3 安装mysql-server)
- 四、启动MySQL
- 五、配置MySQL
-
- [5.1 修改密码](#5.1 修改密码)
- [5.2 设置MySQL允许其他机器登陆root账号](#5.2 设置MySQL允许其他机器登陆root账号)
一、检查是否安装过MySQL
bash
[mall@mall ~]$ rpm -qa | grep mysql
[mall@mall ~]$ rpm -qa | grep mariadb
[mall@mall ~]$ rpm -qa | grep -i -E mysql\|mariadb | xargs -n1 sudo rpm -e --nodeps
二、上传安装包
bash
01_mysql-community-common-5.7.16-1.el7.x86_64.rpm
02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm
03_mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
04_mysql-community-client-5.7.16-1.el7.x86_64.rpm
05_mysql-community-server-5.7.16-1.el7.x86_64.rpm
mysql-connector-java-5.1.27-bin.jar
三、安装MySQL
3.1 安装mysql依赖
bash
[mall@mall mysql]$ sudo rpm -ivh 01_mysql-community-common-5.7.16-1.el7.x86_64.rpm
[mall@mall mysql]$ sudo rpm -ivh 02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm
[mall@mall mysql]$ sudo rpm -ivh 03_mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
3.2 安装mysql-client
bash
[mall@mall mysql]$ sudo rpm -ivh 04_mysql-community-client-5.7.16-1.el7.x86_64.rpm
3.3 安装mysql-server
bash
[mall@mall mysql]$ sudo rpm -ivh 05_mysql-community-server-5.7.16-1.el7.x86_64.rpm
可能会报缺少依赖的错误!执行下面命令即可: [mall@mall mysql]$ sudo yum install libaio
四、启动MySQL
bash
[mall@mall mysql]$ sudo systemctl start mysqld
五、配置MySQL
5.1 修改密码
(1)查看密码
bash
[mall@mall mysql]$ sudo cat /var/log/mysqld.log | grep password
(2)登陆
bash
mysql -uroot -p 'password'
(3)设置复杂密码
bash
mysql> set password=password("Qs23=zs32");
(4)更改mysql密码策略
bash
mysql> set global validate_password_length=4;
mysql> set global validate_password_policy=0;
(5)设置简单密码
bash
mysql> set password=password("123456");
5.2 设置MySQL允许其他机器登陆root账号
(1)进入msyql库
bash
mysql> use mysql
(2)查询user表
bash
mysql> select user, host from user;
(3)修改user表,把Host表内容修改为%
bash
mysql> update user set host="%" where user="root";
(4)刷新
bash
mysql> flush privileges;
(5)退出
bash
mysql> quit;