linux 添加数据库用户

来源:互联网 发布:透视的屏幕软件 编辑:程序博客网 时间:2024/06/07 07:08

第一步:进入MySQL

mysql -uroot msyql -p 回车输入root用户的密码(安装mysql时自己指定的)


创建一个test用户,密码位test,“%“代表联网中的所有用户都能用test用户名访问数据库(所有数据库中的所有表);

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

并将/etc/mysql/mysql.cnf中的bind-address一行注释


访问a_db中的所有表,用如下语句实现

grant all on a_db.*  to 'test'@'%' identified by 'test';


限制权限,限制test用户只能查询a_db中的所有表

grant select on a_db.* to 'test'@'%' identified by 'test';


查看mysql中的所有数据库用户

select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user;


删除test用户

delete from user where User='test' and Host='%';

flush privileges;


删除数据库和数据表

drop database 数据库名;

drop table 数据表名;