mysql ubuntu 開啓3306端口,設置遠程訪問

遠程登錄數據庫的時候出現了下面出錯信息 :
ERROR 2003 ( HY000 ) : Can 't connect to MySQL server on ' xxx.xxx.xxx.xxx ',
通過今天下午的反覆糾結,關於MySql數據庫沒法遠程鏈接的問題能夠歸結爲如下幾點:
1). 沒有授予相應的權限:python

例如,你想root使用123456從任何主機鏈接到mysql服務器mysql

mysql>GRANT ALL PRIVILEGES ON *.* TO ' root '@' % ' IDENTIFIED BY ' 123456 ' WITH GRANT OPTION;
mysql>FLUSH RIVILEGES

若是你想容許用戶jack從ip爲10.10.50.127的主機鏈接到mysql服務器,並使用654321做爲密碼sql

mysql>GRANT ALL PRIVILEGES ON *.* TO ' jack '@’10.10.50.127’ IDENTIFIED BY ' 654321 ' WITH GRANT OPTION;
mysql>FLUSH RIVILEGES

2). 修改mysql數據庫中的user表使相應的用戶能從某一主機登錄數據庫

mysql -u root –p
mysql>use mysql;
mysql>update user set host = ' % ' where user = ' root ';
mysql>select host, user from user;

3). 防火牆禁止了3306端口,以ufw爲例    服務器

root@xxx:~/python_pro/newsite# ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
root@xxx:~/python_pro/newsite# ufw allow 3306
Rule added
Rule added (v6)
root@vultr:~/python_pro/newsite# ufw reload
Firewall reloaded

 


4). 修改MySQL的配置文件
(我這邊是在這個目錄,每一個人目錄不一樣) /etc/mysql/mysql.conf.d/mysqld.cnf,
由於默認3306端口只容許本地訪問的,註釋掉這行less

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.post

#bind-address = 127.0.0.1spa

而後重啓Mysql,service mysql restartrest

相關文章
相關標籤/搜索