Mysql authorizes database creation for non-root users

Mysql authorizes database creation for non-root users

1. The root user builds the database

When using a sub-user to create a table, an error will be reported, as follows

image-20230509142454535

这是因为root用的的权限导致该问题,当前登录用户为metacosmic,此时需要登录root用户

2. Log in to the mysql server

1.mysql -u poot -p
2.输入root账户密码
3.CREATE DATABASE IF NOT EXISTS metacosmic_conference_test default charset utf8mb4 COLLATE utf8mb4_general_ci;
4.show databases;此时可以看见root下的所有库
5.root账号执行,将该库对子用户授权
1.GRANT privileges PRIVILEGES ON metacosmic_conference_test.* to 'metacosmic'@'%';
说明:metacosmic_conference_test为表名,metacosmic为授权用户名;
2.privileges:用户的操作权限,如SELECT,INSERT,UPDATE等;
如果要授予所的权限则使用ALL,则命令为:GRANT ALL PRIVILEGES ON metacosmic_conference_test.* to 'metacosmic'@'%';
如果要授予create和insert权限,则命令为:GRANT CREATE,INSERT PRIVILEGES ON metacosmic_conference_test.* to 'metacosmic'@'%';
3.最后刷新权限表: FLUSH PRIVILEGES;

At this time, my metacosmic user can have the operation authority of AAAA.

image-20230509142657826

3. Verification

执行:
1.exit;
2.mysql -umetacosmic -p

image-20230509143631106

mysql creates a user for the specified database (mysql command creates a user)

How does mysql authorize non-root users to create a database

Guess you like

Origin blog.csdn.net/weixin_45285213/article/details/130579858