记录一下本次为新应用新建数据库用户以及给新建用户分配权限的过程。
注意:mysql 8.0 版本起与以前有一些不一样,关于8.0版本的操作步骤,记录在下面的文章里面了:
(1)新建一个数据库 travel_db
CREATE DATABASE `travel_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
创建 utf8mb4 字符集的:
create database `travel_db` default character set utf8mb4 collate utf8mb4_unicode_ci;
(2)新建一个用户 travelUser1
create user `travelUser1`;
修改用户密码:
update mysql.user set password=password('pwd123#.O') where User='travelUser1';
刷新用户权限:
flush privileges;
只允许该用户 访问 travel_db 库
show grants for `travelUser1`; grant select,update,delete,insert on travel_db.* to `travelUser1`; flush privileges; show grants for `travelUser1`;
刷新用户权限:
flush privileges;
(3)设置 rijiAppUser 能够对 travel_db 库进行所有操作
grant all on travel_db.* to `travelUser1`;
查看用户的权限
show grants for `travelUser1`;
关于mysql用户的相关设置,可参照本站文章: