tified by 'pw123';
mysql> grant all on mydb.* to admin1@'localhost' identified by '123456';
mysql> grant select on mydb.* to admin2@'192.168.0.0/24' identified by '123456';
mysql> grant select,insert on mydb.* to admin3@'%.benet.com' identified by 'pw456';
●查看权限
SHOW GRANTS FOR 用户名@域名或IP
mysql> show grants for root@'localhost';
●撤销权限
REVOKE 权限列表 on 数据库名.表名 from 用户名@域名或者IP
revoke all on mydb.* from admin3@'%.benet.com';
=======================
重置MySQL的root用户密码
●已经知道mysql数据库的root密码
# 方法一:在shell环境中,使用mysqladmin命令设置(需要知道原密码)
[root@CentOS ~]# mysqladmin -u root -p password "123456"
# 方法二:在“mysql>”环境中,使用update命令,直接更新mysql库user表的数据
[root@CentOS ~]# mysql -u root -p
mysql> update mysql.user set password=password('123456') where user='root';
mysql> flush privileges;
# 方法三:在“mysql>”环境中,使用grant命令,修改root用户的授权权限。
mysql>GRANT ALL ON *.* TO root@'localhost' IDENTIFIED BY '123456';
●忘记mysql数据库的root用户的密码
# 关闭mysql服务
service mysqld stop
# 或者
killall mysqld
# 使用myslq_safe脚本以安全模式(不加载授权表)启动mysqld服务(数据库位非默认值需要用--datadir指定)
/usr/local/mysql/bin/mysqld_safe --skip-grant-table --datadir=/var/mysql/data &
# 使用空密码的root用户登录数据库,重新设置root的密码
[root@CentOS ~]# mysql -u root
mysql> update mysql.user set password=password('123456') where user='root';
mysql> flush privileges;