linux下mysql遠程訪問


 

 

 

linux下mysql遠程訪問

Mysql默認root用戶只能本地訪問,不能遠程連接管理mysql數據庫,但項目中必須要遠程導 入導出數據,所以研究了一下。

1 修改localhost

  • 更改 "mysql" 數據庫里的 "user" 表里的 "host" 項,從"localhost"改成"%"
mysql>use mysql;
mysql>update user set host ="%" where user = "root";
mysql>select host, user from user;
mysql>FLUSH PRIVILEGES;
  • 這時的user表應該是這樣的
mysql> select * from user;       
+-----------+------------------+-
| Host      | User             | 
+-----------+------------------+-
| %         | root             | 
| debian    | root             | 
| 127.0.0.1 | root             | 
| ::1       | root             | 
| %         |                  | 
| debian    |                  | 
| %         | debian-sys-maint | 
+-----------+------------------+-
7 rows in set (0.00 sec)         

2 配置/etc/mysql/my.cnf

查看/etc/mysql/my.cnf中,skip-networking 是否已被注掉 sudo gedit /etc/mysql/my.cnf

原:
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address    = 127.0.0.1
#
改為:
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address    = 127.0.0.1
#

3 其他

1 Mysql的端口是否正確

通過netstat -ntlp查看端口占用情況,一般情況下端口是3306。在用工具連接MySQl是要用 到端口。例如My Admin\My Query Browser\MySQl Front等。

2 查看iptables是否停掉,沒關的情況下,無法連接

通過:service iptables stop臨時關閉 報錯:ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.51.112' (113)

Date: \today

Author: machine of awareness

Org version 7.8.06 with Emacs version 23

Validate XHTML 1.0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM