1. 创建用户
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     WITH GRANT OPTION;
mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin_pass';
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> CREATE USER 'dummy'@'localhost';

其中,用户名@后面的localhost代表:该用户只能通过本地进行连接。
%通配符代表在任何的主机都可以连接数据库。

  1. 查看用户权限
mysql> SHOW GRANTS FOR 'admin'@'localhost';
+-----------------------------------------------------+
| Grants for admin@localhost                          |
+-----------------------------------------------------+
| GRANT RELOAD, PROCESS ON *.* TO 'admin'@'localhost' |
+-----------------------------------------------------+
flush privileges;
  1. 删除用户
mysql> DROP USER 'jeffrey'@'localhost';
  1. 修改密码
mysql> ALTER USER 'jeffrey'@'localhost'
    -> IDENTIFIED BY 'mypass';
Logo

更多推荐