mysql用户管理:创建用户
方法一、CREATE USER user1@'localhost' IDENTIFIED BY 'QianFeng@123456';
验证:select * from mysql.user\G;
方法二、GRANT ALL ON *.* TO 'user3'@'localhost' IDENTIFIED BY 'QianFeng@123456';
验证:select * from mysql.user\G;
(再去查询库级权限表中,是否有权限呢?
并没有,因为这是全局权限(所有库)。)
如果想针对某个库分配权限,可以赋予一个用户,针对一个库设置权限。如图一
FLUSH PRIVILEGES; 或重启
查看帮助信息 help grant:
Example 1: Create an account that uses the default authentication
plugin and the given password. Mark the password expired so that the
user must choose a new one at the first connection to the server:
CREATE USER 'jeffrey'@'localhost'
IDENTIFIED BY 'new_password' PASSWORD EXPIRE;
Example 2: Create an account that uses the sha256_password
authentication plugin and the given password. Require that a new
password be chosen every 180 days:
CREATE USER 'jeffrey'@'localhost'
IDENTIFIED WITH sha256_password BY 'new_password'
PASSWORD EXPIRE INTERVAL 180 DAY;
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL ON db1.* TO 'jeffrey'@'localhost';
GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';
ALTER USER 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90;
删除用户方法一如下图:
DROP USER 'user1'@'localhost';
方法二如下图:
修改用户密码:root修改自己密码
方法一如下图:
方法二如下图:
方法三如下图:
root修改其他用户密码:方法一如下图:
方法二如下图:
普通用户修改自己密码如下图:
丢失root用户密码:
# vim /etc/my.cnf
[mysqld]
skip-grant-tables
# service mysqld restart
# mysql -uroot
mysql> UPDATE mysql.user SET authentication_string=password('new_password')
WHERE user='root' AND host='localhost';
mysql> FLUSH PRIVILEGES;
登录和退出mysql如下图:
语法格式如下图:
权限应用的顺序:user (Y|N) ==> db ==> tables_priv ==> columns_priv
grant示例:
赋予权限分以下几种:
回收权限:
查看当前权限:
复制当前权限:
替换grant/revoke,替换to/from