Home > Database > Mysql Tutorial > linuxmysql增加用户,删除用户,以及用户权限_MySQL

linuxmysql增加用户,删除用户,以及用户权限_MySQL

WBOY
Release: 2016-06-01 11:52:29
Original
1064 people have browsed it

一些基本的命令:

登录:

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;

新建用户:
insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
最后三个参数,分别是登录ip,用户名,密码

为用户授权:
格式: grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"; 示例: 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 用户名@'%';

        >drop user 用户名@ localhost;

修改指定用户密码

使用root登录:
mysql -u root -p
执行命令:
update mysql.user set password=password('新密码') where User="test" and Host="localhost";
刷新权限:
flush privileges;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template