安装好mysql后,想本地用Navicat直接远程链接方便一些,结果发现连不上。我第一个想到的就是数据库没有开放远程登陆权限,于是设置明明如下:
1.进入mysql开放权限
bash-4.2# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 399
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
再次链接,又是一样的错误!!!如图:

查看网络端口开放情况:
[root@docker home]# ss -tlnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=1554,fd=13))
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1161,fd=3))
LISTEN 0 100 [::1]:25 [::]:* users:(("master",pid=1554,fd=14))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=1161,fd=4))
果然没有数据3306的端口,也就是说服务器不允许非本地ip访问数据库。
新建用户
CREATE USER ‘data_center’@‘%’ IDENTIFIED BY ‘pass’;
GRANT ALL PRIVILEGES ON . TO ‘data_center’@‘%’ WITH GRANT OPTION;
ALTER USER ‘data_center’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘pass’;
2.配置文件限制远程访问。
可能是配置文件只允许自己本机才能访问,所以就去修改配置文件:
找到
bind-address = 127.0.0.1
或
skip-networking
并注释掉,然后重启mysql。

本文详细介绍了在安装MySQL后遇到的远程连接失败问题及其解决步骤。通过调整数据库权限、检查端口开放情况、创建远程访问用户及修改配置文件,最终实现了Navicat远程连接MySQL的功能。

879

被折叠的 条评论
为什么被折叠?



