1.下载mysql源安装包
$ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2.安装mysql源
$ yum localinstall mysql57-community-release-el7-8.noarch.rpm
3.检查mysql源是否安装成功
$ yum repolist enabled | grep “mysql.-community.”
4.安装MySQL
$ yum install mysql-community-server
5.启动MySQL服务并设置开机启动
$ systemctl start mysqld
$ systemctl enable mysqld
$ systemctl daemon-reload
6.端口开放
$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
$ firewall-cmd --reload
7.修改root本地登录密码 查看mysql密码
$ grep ‘temporary password’ /var/log/mysqld.log
连接mysql
$ mysql -uroot -p
修改密码【注意:后面的分号一定要跟上】
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘新密码’;
或:
mysql> set password for ‘root’@‘localhost’=password(‘新密码’);
8.添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO '账户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
9.如密码等级过高,可通过以下命令调整
set global validate_password_policy=0;