您好,登錄后才能下訂單哦!
用戶部分
如果你需要添加 MySQL 用戶,你只需要在 mysql 數(shù)據(jù)庫(kù)中的 user 表添加新用戶即可。
你可以在創(chuàng)建用戶時(shí),為用戶指定權(quán)限,用戶權(quán)限列表如下:
權(quán)限列表:
ALTER: 修改表和索引。
CREATE: 創(chuàng)建數(shù)據(jù)庫(kù)和表。
DELETE:
刪除表中已有的記錄。
DROP: 拋棄(刪除)數(shù)據(jù)庫(kù)和表。
INDEX: 創(chuàng)建或拋棄索引。
INSERT:
向表中插入新行。
REFERENCE: 未用。
SELECT: 檢索表中的記錄。
UPDATE: 修改現(xiàn)存表記錄。
FILE:
讀或?qū)?a title="云服務(wù)器" target="_blank" href="http://kemok4.com/">云服務(wù)器上的文件。
PROCESS: 查看云服務(wù)器中執(zhí)行的線程信息或殺死線程。
RELOAD:
重載授權(quán)表或清空日志、主機(jī)緩存或表緩存。
SHUTDOWN: 關(guān)閉云服務(wù)器。
ALL: 所有權(quán)限,ALL
PRIVILEGES同義詞。
USAGE: 特殊的 "無權(quán)限" 權(quán)限。
用 戶賬戶包括 "username" 和 "host"
兩部分,后者表示該用戶被允許從何地接入。tom@'%' 表示任何地址,默認(rèn)可以省略。還可以是 "tom@192.168.1.%"、"tom@%.abc.com"
等。數(shù)據(jù)庫(kù)格式為 db@table,可以是 "test.*" 或 "*.*",前者表示 test 數(shù)據(jù)庫(kù)的所有表,后者表示所有數(shù)據(jù)庫(kù)的所有表。
子句
"WITH GRANT OPTION" 表示該用戶可以為其他用戶分配權(quán)限。
以下為添加用戶的的實(shí)例,用戶名為test,密碼為test123,并授權(quán)用戶可進(jìn)行 SELECT, INSERT 和 UPDATE操作權(quán)限:
首先進(jìn)入表:
[root@localhost mysql]# mysql -u root -pEnter password: ****** mysql> use mysql; Database changed
查看MySQL自帶表中的用戶信息:
mysql> select user,authentication_string,host from user; +-----------+-------------------------------------------+-----------+ | user | authentication_string | host | +-----------+-------------------------------------------+-----------+ | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % | +-----------+-------------------------------------------+-----------+
插入用戶test:
mysql> grant select,insert,update,delete,create,drop -> on tutorials.* -> to 'test'@'localhost' -> identified by 'test123'; Query OK, 0 rows affected, 1 warning (0.01 sec)
再次查看用戶列表:
mysql> select user,authentication_string,host from user; +-----------+-------------------------------------------+-----------+ | user | authentication_string | host | +-----------+-------------------------------------------+-----------+ | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % | | test | *676243218923905CF94CB52A3C9D3EB30CE8E20D | localhost | +-----------+-------------------------------------------+-----------+ 4 rows in set (0.00 sec)
刪除test01用戶:
mysql> select user,authentication_string,host from user; +-----------+-------------------------------------------+-----------+ | user | authentication_string | host | +-----------+-------------------------------------------+-----------+ | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % | | test02 | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | loaclhost | | test01 | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | loaclhost | +-----------+-------------------------------------------+-----------+ 5 rows in set (0.00 sec) mysql> drop user test01@loaclhost; Query OK, 0 rows affected (0.00 sec) mysql> select user,authentication_string,host from user; +-----------+-------------------------------------------+-----------+ | user | authentication_string | host | +-----------+-------------------------------------------+-----------+ | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % | | test02 | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | loaclhost | +-----------+-------------------------------------------+-----------+ 4 rows in set (0.00 sec)
重命名test02為test:
mysql> rename user 'test02'@'loaclhost' to 'test'@'192'; Query OK, 0 rows affected (0.00 sec) mysql> select user,authentication_string,host from user; +-----------+-------------------------------------------+-----------+ | user | authentication_string | host | +-----------+-------------------------------------------+-----------+ | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | % | | test | *6691484EA6B50DDDE1926A220DA01FA9E575C18A | 192 | +-----------+-------------------------------------------+-----------+ 4 rows in set (0.00 sec)
撤銷test用戶update權(quán)限:
mysql> revoke update on *.* from 'test'@'192'; Query OK, 0 rows affected (0.01 sec)
MYSQL基本查看的操作
SHOW DATABASES:
列出 MySQL 數(shù)據(jù)庫(kù)管理系統(tǒng)的數(shù)據(jù)庫(kù)列表。
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
USE 數(shù)據(jù)庫(kù)名 :
選擇要操作的Mysql數(shù)據(jù)庫(kù),使用該命令后所有Mysql命令都只針對(duì)該數(shù)據(jù)庫(kù)。
mysql> use sys; Database changed
SHOW TABLES:
顯示指定數(shù)據(jù)庫(kù)的所有表,使用該命令前需要使用 use 命令來選擇要操作的數(shù)據(jù)庫(kù)。
mysql> show tables; +----------------+ | Tables_in_mood | +----------------+ | info | +----------------+ 1 row in set (0.00 sec)
SHOW COLUMNS FROM 數(shù)據(jù)表:
顯示數(shù)據(jù)表的屬性,屬性類型,主鍵信息 ,是否為
NULL,默認(rèn)值等其他信息。
mysql> show columns from info; +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | char(10) | NO | | NULL | | | score | decimal(5,2) | YES | | NULL | | | hobby | int(2) | YES | | NULL | | +-------+--------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
SHOW INDEX FROM 數(shù)據(jù)表:
顯示數(shù)據(jù)表的詳細(xì)索引信息,包括PRIMARY
KEY(主鍵)。
mysql> show index from info; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | info | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.00 sec)
看完MySQL用戶密碼及查看命令的操作方法這篇文章后,很多讀者朋友肯定會(huì)想要了解更多的相關(guān)內(nèi)容,如需獲取更多的行業(yè)信息,可以關(guān)注我們的行業(yè)資訊欄目。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。