下面介绍两种快速mysql开启远程登录方法 有需要学习的朋友可参考一下下。
代码如下 |
复制代码 |
代码如下 |
复制代码 |
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;
|
mysql -u root -p
mysql> use mysql;
mysql> grant all privileges on *.* to root@’%’ identified by “root”;
mysql> select host,user,password from user;
代码如下 |
复制代码 |
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;
|
————– —— ——————————————-
| host | user | password |
————– —— ——————————————-
代码如下 |
复制代码 |
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘myuser’@'192.168.1.3′ IDENTIFIED BY 'mypassword’ WITH GRANT OPTION;
|
| 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