mysql创建账号及管理权限

mysql创建账号及管理权限

0、mysql版本8.0.15,服务器版本:RHEL 6.5

1、创建用户名密码

mysql> use mysql;
mysql> create user 'username'@'%' identified by 'password';

2、赋权

mysql> grant all privileges on *.* to 'username'@'%' with grant option;(授权全部数据库,***危险操作***,(查看PS2))

3、刷新权限

mysql> flush privileges;

PS1:创建用户密码时候报错如下

mysql> create user 'username'@'%' identified  by 'password';
ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 51, found 50. Created with MySQL 80013, now running 80015. Please use mysql_upgrade to fix this error.

百度后是mysql升级后报错,重新升级,之后可以顺利创建mysql用户

[root@localhost bin]# cd /usr/local/mysql/bin/
[root@localhost bin]# mysql -uroot -proot
(执行各种检查升级)

PS2:回收权限

mysql> REVOKE all privileges ON *.* FROM 'username'@'%';(回收所有权限)
mysql> flush privileges;(刷新权限)
mysql> grant all privileges on databasename.* to 'username'@'%' with grant option;(将databasename数据库所有权限赋给username用户)
mysql> flush privileges;(刷新权限)

PS3:赋权命令拆分分析

命令:grant all privileges on databasename.* to 'username'@'%' with grant option
grant/REVOKE                 赋权/回收权限
all privileges 所有权限,可以写成SELECT, INSERT, UPDATE, REFERENCES,
DELETE, CREATE, DROP, ALTER, INDEX,
CREATE VIEW, SHOW VIEW
on
databasename.* 数据库名.数据表 *代表所有
to
'username'@'%'; '用户名'@'所有ip访问'; %代表所有ip访问,可以写具体ip、localhost
上一篇:Java 毫秒转换为日期类型、日期转换为毫秒


下一篇:JS将数字转换为大写汉字人民币