目录
CREATE USER '用户名'@'来源地址' [IDENTIFIED BY [PASSWORD] '密码'];
eg1:使用明文创建用户
CREATE USER 'yzx'@'localhost' IDENTIFIED BY '123123';


- select password('123123');
- create user 'prc'@'localhost' identified by password '*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1';

创建后的用户保存在 mysql 数据库的 user 表里
- use mysql;
- select User,authentication_string,Host from user;

rename user 'tyx'@'localhost' to 'taoyuxin'@'localhost';

drop user 'taoyuxin'@'localhost';

set password = password('123456');


set password for 'yzx@'localhost' = password('123456');

遗忘mysql密码,如下图所示:
修改配置文件,添加配置,使登录mysql不使用授权表
- vim /etc/my.cnf
- #添加此行
- skip-grant-tables

重启服务,登录测试

使用update修改root密码,刷新数据库
update mysql.user set authentication_string = password('acb123') where user = 'root';

退出重新登录测试

再次修改my.conf配置文件,注释掉之前添加的配置命令

GRANT语句:专门用来设置数据库用户的访问权限。当指定的用户名不存在时,GRANT语句将会创建新的用户;当指定的用户名存在时,GRANT 语句用于修改用户信息
GRANT 权限列表 ON 数据库名.表名 TO '用户名'@'来源地址' [IDENTIFIED BY '密码'];

登录并查看库
- mysql -uyxp -pabc123
- show databases;
- use mysql;
- show tables;

grant all on *.* to 'yzx'@'%' identified by '123456';

- SHOW GRANTS FOR 用户名@来源地址;
- show grants for 'yzx'@'localhost';

- show grants for 'yzx'@'localhost';
- revoke select on mysql.* from 'yzx'@'localhost';
