创建mysql数据库用户:
create user tom identified by 'abc123';
异常一
给tom用户使用本地命令行方式,授予test这个库下的所有表的插删改查的权限
报错语句:
grant select,insert,delete,update on test.* to 'tom'@'localhost' identified by 'abc123';
异常信息:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘abc123’’ at line 1
原因:
mysql8.0中已经不支持这种写法了,赋予权限必须分开,先创建用户、再给用户赋值
解决办法:
去掉identified by ‘abc123’
异常二
报错语句:
grant select,update,delete,insert on test.* to 'tom'@'localhost';
异常信息:
ERROR 1410 (42000): You are not allowed to create a user with GRANT
原因:
默认创建用户的主机是 '%'即任意主机
MySQL中查询用户主机:
SELECT HOST,USER FROM mysql.user;
解决办法:
如果想修改为 'localhost’输入以下语句:
UPDATE mysql.user SET HOST=‘localhost’ WHERE USER='tom';
正确语句
GRANT SELECT,UPDATE,DELETE,INSERT ON test.* TO 'tom'@'%';