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

发布时间:2023-04-27 17:53:02 作者:iii
来源:亿速云 阅读:132

本篇内容主要讲解“mysql中grant all privileges on怎么赋给用户远程权限”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“mysql中grant all privileges on怎么赋给用户远程权限”吧!

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

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;

在安装mysql的机器上运行:

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

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

高版本数据库不能按照grant all privileges on *.* to "root"@"%" identified by "xxxx";去修改用户权限

mysql> SELECT @@VERSION;
+-----------+
| @@VERSION |
+-----------+
| 8.0.14    |
+-----------+
1 row in set (0.00 sec)

高版本修改用户权限方法:

# 先创建远程用户,再授权
mysql> create user 'root'@'%' identified by  'password';
Query OK, 0 rows affected (0.03 sec)
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

再次查看发现有了root %

mysql>  select User,Host from user;
+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)
————————————————

mysql授权语句说明grant all privileges、创建用户、删除用户

mysql的赋权语句:

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

刷新权限列表:flush   privileges

CREATE DATABASE 数据库名;
CREATE USER '用户名'@'%' IDENTIFIED BY '密码';    
GRANT all privileges ON 数据库名.* to '用户名'@'%' identified by '密码' WITH GRANT OPTION; 
flush privileges;

创建用户:CREATE USER 'jack'@'localhost' IDENTIFIED BY 'test123';

查看数据库中已经创建的用户:select user,host from user;--user表在数据库自带的、名字为mysql的数据库中

删除用户:delete from user where user = 'jack'; 

drop user ‘jack'@'%';

drop  user  会将该用户的信息全部删掉,而 delete  只会清除user表,其他的比如db表中的信息还是存在。

清除缓存:FLUSH PRIVILEGES

到此,相信大家对“mysql中grant all privileges on怎么赋给用户远程权限”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. mysql使用正则匹配查询关键词的方法
  2. mysql中常用的插入数据的语句

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql

上一篇:node.js对于数据库MySQL基本操作方法有哪些

下一篇:Python协程的实现方式有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》