mysql数据库中创建和删除用户

第一步:进入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;

将创建的用户授权;

GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'%' ;

删除test用户

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

flush privileges;

进入用户

    mysql> use  用户名

显示当前操作用户

    mysql>  show database();

SELECT database();

. 通过show tables实现
    mysql> show tables;
    注:注意查看列头形式, 格式为:Tables_in_[db_name]

. 通过status实现
    mysql> status;

查看user表进入用户为 mysql;

猜你喜欢

转载自wuguowei1314.iteye.com/blog/2333561