linux mysql添加用户,删除用户,以及用户权限

一些主要的命令:

登录:

mysql -u username -p

显示全部的数据库:

show databases;

使用某一个数据库:

use databasename;

显示一个数据库的全部表:

show tables;

退出:

quit;

删除数据库和数据表

mysql>drop database 数据库名;

mysql>drop table 数据表名;

用户相关:

查看全部的用户:

SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

新建用户:

CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456'


为用户授权:

格式:
grant 权限 on 数据库.* to username@登录主机 identified by "password";
演示样例:
grant all privileges on testDB.* to test@localhost identified by '1234';
然后须要运行刷新权限的命令:
flush privileges;

为用户授予部分权限:

grant select,update on testDB.* to test@localhost identified by '1234';

授予一个用户全部数据库的某些权限:

grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

删除用户:

Delete FROM user Where User='test' and Host='localhost';
然后刷新权限;

删除账户及权限:>drop user username@'%';

        >drop user username@ localhost;

改动指定用户password

使用root登录:
mysql -u root -p
运行命令:
update mysql.user set password=password('新密码') where User="test" and Host="localhost";
刷新权限:
flush privileges;


原文地址:https://www.cnblogs.com/zhchoutai/p/6929103.html