1、以管理员身份登录mysql

mysql -u root -p

2、选择mysql数据库

use mysql

3、创建用户并设定密码

create user 'testuser'@'localhost' identified by 'testpassword'

4、使操作生效

flush privileges

5、为用户创建数据库

create database testdb

6、为用户赋予操作数据库testdb的所有权限

grant all privileges on testdb.* to test

user@localhost identified  by 'testpassword';

高版本数据库不能按照

grant all privileges on *.* to "root"@"%" identified by "xxxx";去修改用户权限

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)
 

高版本数据库(mysql 8.0)可按照

use mysql;

update user set plugin='mysql_native_password' where user='trip-map';

select host, user,plugin from user; 

7、使操作生效

flush privileges

8、用新用户登录

mysql -u test -p

mysql8.0 示例

create database trip-map-prd;

create user 'trip-map'@'%' identified by 'trip-xxx';

​grant all privileges on trip_map_prd.* to 'trip-map'@'%' with grant option;

alter user 'trip-map'@'%' identified with mysql_native_password by 'trip-xxx'; 

或 update user set plugin='mysql_native_password' where user='trip-map';

flush privileges

Logo

本社区面向用户介绍CSDN开发云部门内部产品使用和产品迭代功能,产品功能迭代和产品建议更透明和便捷

更多推荐