MySQL遠程訪問權限,允許遠程連接的開啟
1、登陸mysql數據庫
mysql -u root -p
查看user表 www.2cto.com
mysql> use mysql;
Database changed
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
2 rows in set (0.00 sec)
可以看到在user表中已創建的root用戶。host字段表示登錄的主機,其值可以用IP,也可用主機名,
(1)有時想用本地IP登錄,那麼可以將以上的Host值改為自己的Ip即可。
2、實現遠程連接(授權法)
將host字段的值改為%就表示在任何客戶端機器上能以root用戶登錄到mysql服務器,建議在開發時設為%。
update user set host = ’%’ where user = ’root’;
將權限改為ALL PRIVILEGES
mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "root";
Query OK, 0 rows affected (0.00 sec) www.2cto.com
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)
這樣機器就可以以用戶名root密碼root遠程訪問該機器上的MySql.
3、實現遠程連接(改表法)
use mysql;
update user set host = '%' where user = 'root';
這樣在遠端就可以通過root用戶訪問Mysql.
作者 XL.Liang