MySQL相关操作

来源:互联网 发布:sql sum group by 编辑:程序博客网 时间:2024/06/11 00:35

1、查看所有用户:SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

2、删除用户:

mysql>Delete FROM user Where User='test' and Host='localhost';   mysql>flush privileges;   mysql>drop database test.db; //删除用户的数据库删除账户及权限:>drop user 用户名@'%';        >drop user 用户名@ localhost; 

3、新增用户:

insert into mysql.user(Host,User,Password) values("localhost","test",password("123"));

这样就创建了一个名为:test ,密码为:123 的用户。

注意:此处的”localhost”,是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将”localhost”改为”%”,表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。

4、授予权限
授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;

授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):

mysql>grant all privileges on testDB.* to test@localhost identified by '123';
mysql>flush privileges;//刷新系统权限表

5、修改指定用户密码:

mysql>update mysql.user set password=password('新密码') where User="test" and Host="localhost";    mysql>flush privileges;

6、 删除数据库和数据表

mysql>drop database 数据库名;mysql>drop table 数据表名;
0 0
原创粉丝点击