- 查询用户
select user,host from mysql.user;
- 创建客户
# 创建hooware用户,密码为hooware@123456, localhost只能本地连接,%可远程进行连接
create user `hooware`@`%` identified by 'hooware@123456';
# 授予所有权限给hooware用户
grant ALL on *.* to `hooware`@`%` with grant option;
# 刷新用户权限
flush privileges;
- 查看用户
show grants for test;
- 删除用户
--删除用户“test”
drop user test@localhost ;
--若创建的用户允许任何电脑登陆,删除用户如下
drop user test@'%';
- 更改密码
--方法1,密码实时更新;修改用户“test”的密码为“1122”
set password for test =password('1122');
--方法2,需要刷新;修改用户“test”的密码为“1234”
update mysql.user set password=password('1234') where user='test'
--刷新权限
flush privileges;
- 分配权限
--授予用户test通过外网IP对数据库“testdb”的全部权限
grant all privileges on 'testdb'.* to 'test'@'%' identified by '1234';
--刷新权限
flush privileges;
--授予用户“test”通过外网IP对于该数据库“testdb”中表的创建、修改、删除权限,以及表数据的增删查改权限
grant create,alter,drop,select,insert,update,delete on testdb.* to test@'%';
- 创建数据库
--创建名称为“testdb”数据库,并设定编码集为utf8mb4
CREATE DATABASE IF NOT EXISTS testdb DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
Q.E.D.