| SET PASSWORD FOR 'root'@'localhost'="Chen123456."; exit; |
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下所示:
ALTER USER ‘root'@'localhost' IDENTIFIED BY ‘MyNewPass4!';
set password for ‘root'@'localhost'=password(‘MyNewPass4!');
通过msyql环境变量可以查看密码策略的相关信息:
| mysql> show variables like ‘%password%'; |

如果上面的方式不能修改可以使用下面安全模式修改root:
关闭服务
systemctl stop mysqld.service
vi /etc/my.cnf
mysqld下面添加skip-grant-tables 保存退出启动服务
systemctl start mysqld.service
mysql -u root 不用密码直接回车
use mysql
update user set authentication_string=password(‘Root-123') where User='root'and Host='localhost';
flush privileges;
exit;
vi /etc/my.cnf 把 skip-grant-tables 一句删除保存退出重启mysql服务
systemctl restart mysqld.service
再次登录即可
mysql -u root -pRoot-123
如果进行操作出现下面的提示:
You must reset your password using ALTER USER statement before executing thisstatement.
就再设置一遍密码
set password = password(‘Root-123');
开放3306端口(允许使用用户名root密码Root-123456从任何主机连接到mysql服务器)
| mysql>grant all on root.* to root@'%' identified by 'vmroot!@#456VMROOT'; mysql>FLUSH PRIVILEGES; mysql>exit; |
开启防火墙mysql 3306端口的外部访问
| firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd--reload |
配置默认编码为utf8
| vi /etc/my.cnf |
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
| [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8' |
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

如果想使用防火墙,建议使用以下方法配置:
关闭firewall:
| systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 |
安装iptables防火墙:








