用navicat连接远程连接mysql,报错不知道原因。mysql安装在云服务器上ubantu,liunx基本不接触。。。。,安装ubantu也只是想练练linux。
第一个错 Can't connect to MySQL server xxx.xxx.xxx.xxx (10061)
查---
说是配置文件/etc/mysql/my
.cnf
中bind-address = 127.0.0.1要注释掉,改了以后重启mysql(命令service mysql restart),重启后这个报错不见了,但又出现了其他问题,说要用ssh模式连接(https://blog.csdn.net/qq_42576040/article/details/86533087),于是用了ssh模式,但还是不行
第二个错没记下来,查到要加权限,加上权限,还查看了3306端口是否对外开放(sudo netstat -tlpn),然后发现错误又变了。
进入mysql,运行以下
use mysql
update user set host='%' where user='root';
flush privileges
第三个错 ssh tunnel:server does not support diffie-hellman-group1-sha1 forkeyexchange
网上找的的答案说在 /etc/ssh/sshd_config最下面加入下面配置
KexAlgorithms diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
Ciphers 3des-cbc,blowfish-cbc,aes128-cbc,aes128-ctr,aes256-ctr
执行ssh-keygen命令
ssh-keygen -A
重启ssh
service sshd restart
按这个做了,执行重启是就报错了
重启ssh服务时提示:Job for ssh.service failed because the control process exited with error code
说明加的东西造成的
既然第三个错误“not support diffie-hellman-group1-sha1”不支持“diffie-hellman-group1-sha1”,那我干嘛加这么多,于是只加了以下
KexAlgorithms diffie-hellman-group1-sha1
Ciphers 3des-cbc
继续执行ssh-keygen命令,重启ssh
成功执行
继续用navicat连数据库
第四个错Client does not support authentication protocol requested by server,还是验证问题
USE mysql;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxx';
FLUSH PRIVILEGES;
root是用户名
localhost是ip地址127.0.0.1都是特指本机,%表示任何IP都可访问
mysql_native_password是旧的密码验证机制,xxxx是密码,最后别忘了分号;
改完以后终于连接成功了,并且不用ssh也可以连接成功