Linux之CentOS7安装MySQL-5.7.29

卸载之前的版本

# 卸载之前的版本
rpm -qa|grep mysql
yum remove mysql-libs

# 注意:
# 有的系统可能不太一样,没有mysql-libs,而是mariadb-libs,此时要移除的则是mariadb-libs
rpm -qa|grep mariadb
yum remove mariadb-libs

下载安装包

# 下载安装包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.29-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.29-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.29-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.29-1.el7.x86_64.rpm

安装MySQL

# 安装:注意这里的安装顺序
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm

设置MySQL服务

# 查看MySQL状态
systemctl status mysqld.service
​
# 开启MySQL服务
systemctl enable mysqld.service
​
# 启动MySQL服务
systemctl start mysqld.service

修改数据库登录密码

# 查看root账户临时密码
grep "password" /var/log/mysqld.log
​
# 连接MySQL数据库
mysql -uroot -p # 输入上一步查看到的密码
​
# 修改MySQL root登录密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
# 不成功,出现
Your password does not satisfy the current policy requirements
# 解决方案如下
set global validate_password_policy=LOW;  #设置密码等级
set global validate_password_length=6;    #设置密码长度
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';  #修改root密码

查看密码策略

# 查看密码策略
SHOW VARIABLES LIKE 'validate_password%';

设置远程连接

# 远程连接设置
mysql -uroot -p
use mysql; #使用mysql数据库
update user set host='%' where user='root';
flush privileges;

设置防火墙策略

# 查看防火墙状态
systemctl status firewalld
# 或者
firewall-cmd --state

# 设置mysql端口可以远程访问
firewall-cmd --permanent --zone=public --add-port=3306/tcp

# 重新加载
firewall-cmd --reload

# 查看3306端口状态
firewall-cmd --zone=public --query-port=3306/tcp

这样可以通过Navicat,SQLyog或者其他远程工具连接了。

你可能感兴趣的:(Linux)