创建用户
CREATE USER ch IDENTIFIED BY '123456';
授权
- 所有权限
GRANT ALL PRIVILEGES ON *.* TO 'ch'@'%' IDENTIFIED BY '123456';
给ch用户所有数据库权限,“%”的意思是允许所有机器远程连接该库
注意:GRANT ALL PRIVILEGES ON . TO 'ch'@'%' (这样是报错的)
ERROR 1133 (42000): Can't find any matching row in the user table
- 指定权限
GRANT SELECT, UPDATE, INSERT, DELETE ON test.* TO 'ch'@'192.168.1.168' IDENTIFIED BY '123456';
给ch用户test库的 CRUD 权限,并且只有 '192.168.1.168' 机器可以远程连接该库
运行 flush privileges
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
让修改生效