准备:
- VirtualBox
- Centos7
- MySQL 5.7
1、从 MySQL 官网下载,mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar
,
tar -xvf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar -C mysql-5.7 # 解压
解压的文件:
2、 执行命令安装:
yum install mysql-community-{
server,client,common,libs}-* mysql-5.*
配置文件在:/etc/my.cnf
。
3、启动 mysql 服务:
systemctl start mysqld
4、设置 root 密码
mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password'; # 修改root密码
设置密码的时候有可能出现:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
这是 mysql 密码策略的问题,
show variables like 'validate_password%'; # 查看密码策略
set global validate_password_policy=LOW; # 修改密码策略
参考:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
5、远程登录
5.1 关闭防火墙
如果有报上面这个错,执行命令关闭防火墙:
systemctl stop firewalld.service
5.2 让 MySQL 允许远程登录
继续使用 Navicat Premium
访问出现如下错误:
登录 mysql 修改配置:
mysql> use mysql
mysql> select host from user where user = 'root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
mysql> FLUSH PRIVILEGES;
mysql>