设置Ubuntu允许远程连接MySQL

2014-11-24 17:13:35 · 作者: · 浏览: 2

1、 登录 Mysql-Server 连接本地 mysql (默认只允许本地连接)
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\kuco>mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.45-community-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


2, 修改 Mysql-Server 用户配置


mysql> USE mysql; -- 切换到 mysql DB
Database changed
mysql> SELECT User, Password, Host FROM user; -- 查看现有用户,密码及允许连接的主机
+------+----------+-----------+
| User | Password | Host |
+------+----------+-----------+
| root | | localhost |
+------+----------+-----------+
1 row in set (0.00 sec)

mysql> -- 只有一个默认的 root 用户, 密码为空, 只允许 localhost 连接
mysql> -- 下面我们另外添加一个新的 root 用户, 密码为空, 只允许 192.168.1.100 连接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;
或允许所有ip访问: mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY '';

mysql> -- 当然我们也可以直接用 UPDATE 更新 root 用户 Host, 但不推荐, SQL如下:
mysql> -- UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1;


3、 修改 Mysql 配置文件 my.ini


sudo vim /etc/mysql


bind-address = 127.0.0.1
将 bind-address = 127.0.0.1 这一行注释掉, 即修改为:
#bind-address = 127.0.0.1
到此 Mysql-Server 端配置就完成了.


然后重启 MySQL
$> sudo /etc/init.d/mysql restart
* Starting MySQL database server mysqld
...done.
* Checking for corrupt, not cleanly closed and upgrade needing tables.
linuxidc@ubuntu:~$ sudo /etc/init.d/mysql start
* Starting MySQL database server mysqld
...done.


配置到这一步就可以使用Mysql客户端工具远程链接了。


--------------------------------------分割线 --------------------------------------


--------------------------------------分割线 --------------------------------------