mysql中grant all privileges on赋给用户远程权限

版权声明:©来自CSDN博客作者"李在奋斗"的原创作品,如需转载,请注明出处 https://blog.csdn.net/qq_31725371/article/details/83019856

mysql中grant all privileges on赋给用户远程权限

  • 改表法。

当你的帐号不允许从远程登陆,只能在localhost连接时。这个时候只要在mysql服务器上,更改 mysql 数据库里的 user 表里的 host 项,从localhost"改成%即可实现用户远程登录

在安装mysql的机器上运行:

1. mysql -u root -p  

2. select host,user from user where user='root';

3. update user set host = '%' where user='root' and host='localhost';  

4. select host, user from user where user='root';

  • 授权法
[root@aaa-server ~]# mysql -u root -p
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123' with grant option;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye


  • 授权法。

例如,你想user使用mypwd从任何主机连接到mysql服务器的话。

在安装mysql的机器上运行:

1. GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'mypwd' WITH

      GRANT OPTION;  

2.FLUSH   PRIVILEGES;


模板:
grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option;
flush privileges;
  • 如果你想允许用户user从ip为192.168.1.4的主机连接到mysql服务器,并使用mypwd作为密码

在安装mysql的机器上运行:

 GRANT ALL PRIVILEGES ON *.* TO 'user'@'192.168.1.3' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;   

 FLUSH   PRIVILEGES;

注意授权后必须FLUSH PRIVILEGES;否则无法立即生效。

猜你喜欢

转载自blog.csdn.net/qq_31725371/article/details/83019856
今日推荐