MySql增加用戶、授權(quán)、修改密碼等語(yǔ)句
MySql增加用戶、授權(quán)、修改密碼等語(yǔ)句
數(shù)據(jù)庫(kù)top_develop
登錄數(shù)據(jù)庫(kù)
1:新增用戶
[mysql@lcamdb ~]$ mysql -u root -p
Enter password: *****
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>use mysql
mysql> insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) values("localhost","top_hdz",password("top_hdz"),'','','');
Query OK, 1 row affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT host, user, password FROM user WHERE user = "top_hdz";
+-----------+---------+-------------------------------------------+
| host | user | password |
+-----------+---------+-------------------------------------------+
| localhost | top_hdz | *9E2182EFC0FDC01E6EDC9FE113C4158587B31889 |
+-----------+---------+-------------------------------------------+
1 row in set (0.00 sec)
進(jìn)行登錄測(cè)試
[mysql@lcamdb mysql]$ mysql -u top_hdz -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.6.17 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use top_develop
ERROR 1044 (42000): Access denied for user 'top_hdz'@'localhost' to database 'top_develop'
2:進(jìn)行授權(quán),訪問(wèn)top_develop 數(shù)據(jù)庫(kù)所有對(duì)象的權(quán)限
grant all privileges on top_develop.* to top_hdz@localhost identified by 'top_hdz';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
權(quán)限添加之后:
mysql> use top_develop
ERROR 1044 (42000): Access denied for user 'top_hdz'@'localhost' to database 'top_develop'
mysql> use top_develop
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> exit
Bye
如果想指定部分權(quán)限給一用戶,可以這樣來(lái)寫:
mysql>grant select,update on top_develop.*
3.刪除用戶。
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User="top_hdz" and Host="localhost";
mysql>flush privileges;
//刪除用戶的數(shù)據(jù)庫(kù)
mysql>drop database top_develop;
4.修改指定用戶密碼。
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="top_hdz" and Host="localhost";
mysql>flush privileges;
5.列出所有數(shù)據(jù)庫(kù)
mysql>show database;
6.切換數(shù)據(jù)庫(kù)
mysql>use '數(shù)據(jù)庫(kù)名';
7.列出所有表
mysql>show tables;
8.顯示數(shù)據(jù)表結(jié)構(gòu)
mysql>describe 表名;
9.刪除數(shù)據(jù)庫(kù)和數(shù)據(jù)表
mysql>drop database 數(shù)據(jù)庫(kù)名;
mysql>drop table 數(shù)據(jù)表名;