mysql中grant?all?privileges?on怎么赋给用户远程权限
本篇内容主要讲解“mysql中grantallprivilegeson怎么赋给用户远程权限”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“mysql中grantallprivilegeson怎么赋给用户远程权限”吧!
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-uroot-pMariaDB[(none)]>grantallprivilegeson*.*toroot@'%'identifiedby'123'withgrantoption;QueryOK,0rowsaffected(0.00sec)MariaDB[(none)]>flushprivileges;QueryOK,0rowsaffected(0.01sec)MariaDB[(none)]>flushprivileges;QueryOK,0rowsaffected(0.00sec)MariaDB[(none)]>exitBye
授权法。
例如,你想user使用mypwd从任何主机连接到mysql服务器的话。
在安装mysql的机器上运行:
1.GRANTALLPRIVILEGESON*.*TO'user'@'%'IDENTIFIEDBY'mypwd'WITHGRANTOPTION;2.FLUSHPRIVILEGES;模板:grantallprivilegeson库名.表名to'用户名'@'IP地址'identifiedby'密码'withgrantoption;flushprivileges;
如果你想允许用户user从ip为192.168.1.4的主机连接到mysql服务器,并使用mypwd作为密码
在安装mysql的机器上运行:
GRANTALLPRIVILEGESON*.*TO'user'@'192.168.1.3'IDENTIFIEDBY'mypwd'WITHGRANTOPTION;FLUSHPRIVILEGES;
注意授权后必须FLUSH PRIVILEGES;否则无法立即生效。
高版本数据库不能按照grant all privileges on *.* to "root"@"%" identified by "xxxx";去修改用户权限
mysql>SELECT@@VERSION;+-----------+|@@VERSION|+-----------+|8.0.14|+-----------+1rowinset(0.00sec)
高版本修改用户权限方法:
#先创建远程用户,再授权mysql>createuser'root'@'%'identifiedby'password';QueryOK,0rowsaffected(0.03sec)mysql>grantallprivilegeson*.*to'root'@'%'withgrantoption;QueryOK,0rowsaffected(0.01sec)mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)
再次查看发现有了root %
mysql>selectUser,Hostfromuser;+------------------+-----------+|User|Host|+------------------+-----------+|root|%||mysql.infoschema|localhost||mysql.session|localhost||mysql.sys|localhost||root|localhost|+------------------+-----------+5rowsinset(0.00sec)————————————————
mysql授权语句说明grant all privileges、创建用户、删除用户
mysql的赋权语句:
grantallprivilegeson*.*to'root'@'%'identifiedby'123456'withgrantoption;
all privileges==》 表示所有的权限 ,增删改查权限全部都有了
*.* ==> 所有的数据库下面所有的表
root@%==》 所有数据库下面所有的表,所有的权限,全部都给root用户% 表示root用户可以在任意机器上面进行连接登录
identified by '123456'==》远程登录连接的密码
刷新权限列表:flushprivileges
CREATEDATABASE数据库名;CREATEUSER'用户名'@'%'IDENTIFIEDBY'密码';GRANTallprivilegesON数据库名.*to'用户名'@'%'identifiedby'密码'WITHGRANTOPTION;flushprivileges;
创建用户:CREATE USER 'jack'@'localhost' IDENTIFIED BY 'test123';
查看数据库中已经创建的用户:select user,host from user;--user表在数据库自带的、名字为mysql的数据库中
删除用户:delete from user where user = 'jack';
dropuser‘jack'@'%';
drop user 会将该用户的信息全部删掉,而 delete 只会清除user表,其他的比如db表中的信息还是存在。
清除缓存:FLUSH PRIVILEGES
到此,相信大家对“mysql中grantallprivilegeson怎么赋给用户远程权限”有了更深的了解,不妨来实际操作一番吧!这里是主机评测网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
上一篇:java中export方法怎么实现导出excel文件