## 创建用户,如果是任意位置,则 host 为 % CREATE USER 'username'@'host' IDENTIFIED BY 'password';
## 传统密码测试 CREATE USER 'username'@'host' IDENTIFIED WITH mysql_native_password BY 'password';
## 授予权限 GRANT privileges[权限列表] ON databasename.tablename TO username;
## 授予全部权限 GRANT ALL ON *.* TO user;
## 例 GRANT ALL ON phkj.* TO 'phkj'@'localhost';
GRANT ALL ON phkj.* TO user;
## mysql8.0,其中*.*第一个*表示所有数据库,第二个*表示所有数据表,如果不想授权全部那就把对应的*写成相应数据库或者数据表;username为指定的用户;%为该用户登录的域名 grant all privileges on *.* to 'username'@'%' with grant option;
## 刷新权限 flush privileges;
## 查看所有用户 select * from mysql.user;
## 删除用户 Delete FROM mysql.user Where User='test' and Host='localhost';
## 修改用户的host属性 UPDATE mysql.user SET Host='%' WHERE Host='localhost' AND User='username'; FLUSH PRIVILEGES;
## 查看某个用户的权限 show grants for'xxx'@'%'; ## or select * from mysql.user where user='root' \G;
## 错误,总是提示语法错误。 update user set password=password('passwd') where user='jack'; GRANT USAFE ON . TO ‘username’@’localhost’ IDENTIFIED BY [PASSWORD] ‘new_password’;
## 正确 ## 第一种 update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
## 第二种 alter user 'root'@'localhost' identified by '123';
## 第三种 set password for'root'@'localhost'=password('123');