mysql -u root -p
mysql> use mysql;
mysql> grant all privileges on *.* to root@’%’ identified by “root”;
mysql> select host,user,password from user;
+————–+——+——————————————-+
| host | user | password |
+————–+——+——————————————-+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| 192.168.1.12 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+————–+——+——————————————-+
3 rows in set (0.00 sec)
mysql> flush privileges;
授權法:
例如,你想myuser使用mypassword從任何主機連接到mysql服務器的話。
代碼如下 復制代碼mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;
如果你想允許用戶myuser從ip為192.168.1.6的主機連接到mysql服務器,並使用mypassword作為密碼
代碼如下 復制代碼mysql> GRANT ALL PRIVILEGES ON *.* TO ‘myuser’@'192.168.1.3′ IDENTIFIED BY 'mypassword’ WITH GRANT OPTION;
注意:
1、格式:grant 權限 on 數據庫名.表名 to 用戶@登錄主機 identified by “用戶密碼”;
2、是新增ROOT不是修改,如果把localhost改為%,那麼本地就無法通過localhost連接mysql了;
3、刷新MySQL的系統權限相關表 flush privileges;
更多相關開啟mysql遠程連接可參考:http://www.111cn.net/database/mysql/34989.htm