环境准备
- 服务器上安装MySQL数据库
- 客户机上安装Navicat Premium 15
- 准备好自己服务器的ip地址、服务器登陆密码、mysql数据库的密码
服务器开启远程权限
- 在服务器的安全组规则上开放3306端口
- 登录mysql数据库执行一下操作
一个是要开放root登录权限给所有人,二是要查看是不是使用3306端口登录
记住,一定要刷新权限!!不然有可能测试连接通过了,但是实际连接却连接不上mysql> use mysql mysql> select Host,User from user; +-----------+------------------+ | Host | User | +-----------+------------------+ | localhost | root | | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | +-----------+------------------+ 4 rows in set (0.00 sec) mysql> update user set host='%' where user = 'root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select Host,User from user; +-----------+------------------+ | Host | User | +-----------+------------------+ | % | root | | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | +-----------+------------------+ 4 rows in set (0.00 sec) mysql> show variables like '%port%'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | admin_port | 33062 | | large_files_support | ON | | mysqlx_port | 33060 | | mysqlx_port_open_timeout | 0 | | port | 3306 | | report_host | | | report_password | | | report_port | 3306 | | report_user | | | require_secure_transport | OFF | +--------------------------+-------+ 10 rows in set (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.22 sec)
Navicat 连接 Mysql
- 新建一个连接,先在SSH那里填写服务器的信息
- 点击常规,填写数据库的配置
- 如果测试连接通过了,但是确定之后连接却失败,这种情况可能是没有刷新权限,要去数据库中执行语句
flush privileges;
即可