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

网友投稿 2281 2023-07-08

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 -pMariaDB [(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)]> exitBye登录后复制

授权法。

例如,你想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;否则无法立即生效。

高版本数据库不能按照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;登录后复制

all privileges ==》 表示所有的权限 ,增删改查权限全部都有了*.* ==> 所有的数据库下面所有的表root@% ==》 所有数据库下面所有的表,所有的权限,全部都给root用户 % 表示root用户可以在任意机器上面进行连接登录The password used for remote login connection is "123456".

刷新权限列表: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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系小编 edito_r@163.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:mysql一对多关系怎么理解
下一篇:mysql 8.0.26安装配置的方法
相关文章