时间:2021-07-01 10:21:17 帮助过:9人阅读
1. 新增用户 Sql代码 mysql insert into mysql. user (Host, User , Password ) values ( localhost , lionbule , password ( hello1234 )); mysqlflush privileges ; 或者 CREATEUSER ' username'@'host 'IDENTIFIEDBY'password'; 例子:CREATEUSER'dog'@'lo
1. 新增用户
Sql代码
或者
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
例子: CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';
2. 修改用户密码
Sql代码
或
a. 使用mysqladmin语法:mysqladmin -u用户名 -p旧密码 password 新密码
例如:mysqladmin -u root -p 123 password 456;
或者
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
如果是当前登陆用户用SET PASSWORD = PASSWORD("newpassword");
3. 删除用户
Sql代码
或者
drop user username@'%'
drop user username@localhost
4. 权限分配
4.1. grant用法
grant 权限 on 数据库.* to 用户名@'登录主机' identified by '密码'
Doc代码
取消授权用户:
语法:REVOKE privilege ON databasename.tablename FROM 'username'@'host';
例子: REVOKE SELECT ON *.* FROM 'pig'@'%';
REVOKE SELECT ON test.user FROM 'pig'@'%';
revoke all on *.* from sss@localhost ;
revoke all on user.* from 'admin'@'%';
SHOW GRANTS FOR 'pig'@'%'; //查看授权
取消授权用户:
语法:REVOKE privilege ON databasename.tablename FROM 'username'@'host';
例子: REVOKE SELECT ON *.* FROM 'pig'@'%';
REVOKE SELECT ON test.user FROM 'pig'@'%';
revoke all on *.* from sss@localhost ;
revoke all on user.* from 'admin'@'%';
SHOW GRANTS FOR 'pig'@'%'; //查看授权