在本地使用mysql -h192.168.1.130 -P3306 -uroot -proot 不能登录,在远程mysql服务器中使用mysql -uroot -proot 能够登录

在本地使用

MySQL Server 5.7\bin>mysql -h192.168.1.130 -P3306 -uroot -proot  

登录远程mysql 出现一下错误。

Warning: Using a password on the command line interface can be insecure.

ERROR 2003 (HY000): Can't connect to MySQL server on '10.34.16.100' (10061)

原因是ip地址为mysql不能监听到私有ip。在远程mysql中找到mysql.cnf 文件将

bind-address = 127.0.0.1   

这项配置注释或改为

bind-address = 0.0.0.0    //用于监听所有ip

之后重启mysql 服务器

sudo systemctl  restart mysql      // ubuntu中命令  

再次在本地登录

mysql -h192.168.1.130 -P3306 -uroot -proot

可能会返回

Warning: Using a password on the command line interface can be insecure.

ERROR 1130 (HY000): Host '192.168.1.130' is not allowed to connect to this MySQL

是因为192.168.1.130 没有访问数据库的权限,在远程mysql 服务器中使用root权限登录

create user  'your user name'@'192.168.1.130' identified by 'your password';     -- 为此连接创建一个新用户, 不需要为其分配新用户可以直接授权

grant all privileges on *.* to 'your user name'@'192.168.1.130' identified by 'your password' ; -- 对新创建的用户授权,all privileges 表示授予其root, 此项可根据自己的选择只授予select update insert 或delete 权限。

flush privileges ;

在本地使用新用户登录()

mysql -h192.168.1.130 -P3306 -u'your user name'  -p'your password'

应该就能登录到远程mysql

你可能感兴趣的:(在本地使用mysql -h192.168.1.130 -P3306 -uroot -proot 不能登录,在远程mysql服务器中使用mysql -uroot -proot 能够登录)