本地Navicat Premium连接数据库报错
Can't connect to MySQL server on '127.0.0.1' (61)
先进行以下尝试
1.本地连接虚拟机的iptelnet 192.168.33.11
//出现一下错误
elnet: connect to address 192.168.33.11: Connection refused
telnet: Unable to connect to remote host
2.虚拟机安装telnetsudo apt-get install telnetd
sudo netstat -a | grep telnet
tcp 0 0 *:telnet *:* LISTEN
本机再次尝试 telnet 192.168.33.11 已经可以连接..
3.本机尝试telnet 192.168.33.11 3306
telnet: connect to address 192.168.33.11: Connection refused
telnet: Unable to connect to remote host
//虚拟机查看端口
netstat -an|grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
把
bind-address = 127.0.0.1
修改
bind-address = 0.0.0.0
sudo service mysql restart
//再次虚拟机查看端口
netstat -an|grep 3306
tcp6 0 0 :::3306 :::* LISTEN
Navicat Premium 连接错误
Access denied for user 'root'@'192.168.33.1' (using password: YES)虚拟机进入 mysql -uroot -p123456
grant all privileges on *.* to root@'%' identified by '123456';
//表示root用户可以在任何ip都可以访问任何库的任何对象,密码是123456生产上,按实际情况而定。
flush privileges;//刷新权限
执行上面命令再次尝试已经可以连接