在本地使用
MySQL Server 5.7\bin>mysql -h192.168.1.130 -P3306 -uroot -proot ?
登錄遠程mysql 出現(xiàn)一下錯誤。
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不能監(jiān)聽到私有ip箫津。在遠程mysql中找到mysql.cnf 文件將
bind-address = 127.0.0.1 ??
這項配置注釋或改為
bind-address = 0.0.0.0 ? ?//用于監(jiān)聽所有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'; ? ? -- 為此連接創(chuàng)建一個新用戶, 不需要為其分配新用戶可以直接授權
grant all privileges on *.* to 'your user name'@'192.168.1.130' identified by 'your password' ; -- 對新創(chuàng)建的用戶授權回季,all privileges 表示授予其root, 此項可根據自己的選擇只授予select update insert 或delete 權限正林。
flush privileges 泡一;
在本地使用新用戶登錄()
mysql -h192.168.1.130 -P3306 -u'your user name' ?-p'your password'
應該就能登錄到遠程mysql