用root登录执行:
use mysql;
create user user_name;
grant privileges on database_name.table_name to 'user_name'@'host' identified by 'pass_word';
flush privileges;
这里:
- privileges
:select
、insert
、update
等,所有权限写all
- host
:IP或主机名,所有IP或主机名写%
注意,若出现从localhost
无法登录的情况,例如:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
原因多种多样。最简单的办法是对localhost
再授权一下:
grant privileges on database_name.table_name to 'user_name'@'localhost';