创建用户并授权:
# 创建数据库
create database db_example;
# 创建用户 (用户名@连接ip by 密码)
create user 'user_example'@'localhost' identified by 'password'
# 授权
grant all on db_example.* to 'user_example'@'localhost';
如需远程连接,可以将“localhost”修改改为“%”:
create user 'user_example'@'%' identified by 'password'
或者手动修改权限:
# 访问mysql库
use mysql;
# 使user_example能再任何host访问
update user set host = '%' where user = 'user_example';
flush privileges;