博客园  :: 首页  :: 联系 :: 管理

linux下mysql远程访问

Posted on 2013-09-12 16:24  雪庭  阅读(13370)  评论(0编辑  收藏  举报

 

 

 

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