Linux环境 Mysql新建用户和数据库并受权

1.登陆mysqlmysql

#mysql -u root -psql

2.新增用户数据库

insert into mysql.user(Host,User,Password) values("localhost","xxx",password("***"));ide

注释:xxx为新建用户名,***为用户密码it

3.执行该句后,还须要刷新权限表class

flush privileges;test

4.新建数据库并赋予用户权限
create database dbtest;登录

所有受权:
容许本地登陆
grant all privileges on dbtest.* to xxx@localhost identified by "*";
容许任何主机登陆
grant all privileges on dbtest. to xxx@'%' identified by "
";
部分受权:
grant select,update on dbtest.* to xxx@localhost identified by "***";date

5.赋予权限,还须要再刷新权限表select

flush privileges;

6.经过sql语句查询出新增结果

select user,host,password from mysql.user;

7.删除用户

delete from user where user=‘xxx’;
flush privileges;

8.删除数据库

drop database dbtest;

9.修改密码

update mysql.user set password=password(‘新密码’) where User='xxx' and Host='localhost';flush privileges;

相关文章
相关标签/搜索