在机器上登录MySQL
mysql -u root -p
1、创建用户
create user '用户名'@'localhost' identified by '密码';
create user '用户名'@'%' identified by '密码';
2、刷新MySQL的系统权限相关表
flush privileges;
3、创建数据库,编码格式建议为utf8mb4
create database 数据库名 DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
4、对用户进行赋权,‘连接口令’不能为空,否则创建失败。
grant all privileges on `数据库`.* to '用户名'@'%' identified by '密码';
grant all privileges on `数据库`.* to '用户名'@'localhost' identified by '密码';
6、刷新MySQL的系统权限相关表
flush privileges;