MySQL数据库命令行用户管理(咋个办呢 zgbn)

MySQL数据库命令行用户管理

登录MySQL数据库

  1. 登录MySQL
[root@dstest2-db ~]# mysql -uroot -p密码
字段描述
root最高权限用户名
密码登录密码

2. 选择mysql数据库

mysql> use mysql;
... ...
Database changed
  1. 查看数据库所有表
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
... ...
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

mysql> 
  1. 查看当前用户
mysql> select host , user from user ;
+---------------+---------------+
| host          | user          |
+---------------+---------------+
| localhost     | mysql.session |
| localhost     | mysql.sys     |
| localhost     | root          |
+---------------+---------------+
3 rows in set (0.00 sec)

mysql> 

创建用户

命令:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
字段描述词典
username☞将创建的用户名
host☞指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,从任意远程主机登陆可以使用通配符%localhost
%
password该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器。

授权用户

  1. 将数据库实例授权给用户
# 命令:
GRANT privileges ON databasename.tablename TO 'username'@'host';
字段描述词典
privileges用户的操作权限,授予所的权限则使用ALL。SELECT
INSERT
UPDATE
等(参见权限表)
ALL
databasename数据库名
tablename表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*.*表示

2. 修改用户连接权限

命令:
GRANT ALL PRIVILEGES  ON *.* TO root@'%' IDENTIFIED BY "password" ;

创建一个拥有所有权限的root用户,可以远程任意主机连接。

权限操作表

权限描述
ALTERAllows use of ALTER TABLE.
ALTER ROUTINEAlters or drops stored routines.
CREATEAllows use of CREATE TABLE.
CREATE ROUTINECreates stored routines.
CREATE TEMPORARY TABLEAllows use of CREATE TEMPORARY TABLE.
CREATE USERAllows use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES.
CREATE VIEWAllows use of CREATE VIEW.
DELETEAllows use of DELETE.
DROPAllows use of DROP TABLE.
EXECUTEAllows the user to run stored routines.
FILEAllows use of SELECT… INTO OUTFILE and LOAD DATA INFILE.
INDEXAllows use of CREATE INDEX and DROP INDEX.
INSERTAllows use of INSERT.
LOCK TABLESAllows use of LOCK TABLES on tables for which the user also has SELECT privileges.
PROCESSAllows use of SHOW FULL PROCESSLIST.
RELOADAllows use of FLUSH.
REPLICATIONAllows the user to ask where slave or master
CLIENTservers are.
REPLICATION SLAVENeeded for replication slaves.
SELECTAllows use of SELECT.
SHOW DATABASESAllows use of SHOW DATABASES.
SHOW VIEWAllows use of SHOW CREATE VIEW.
SHUTDOWNAllows use of mysqladmin shutdown.
SUPERAllows use of CHANGE MASTER, KILL, PURGE MASTER LOGS, and SET GLOBAL SQL statements. Allows mysqladmin debug command. Allows one extra connection to be made if maximum connections are reached.
UPDATEAllows use of UPDATE.
USAGEAllows connection without any specific privileges.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值