mysql系統資訊函數有:1、使用【SHOW PROCESSLIST】指令輸出目前使用者的連線資訊;2、使用【CHARSET()】函數傳回字串使用的字元集;3、使用【COLLATION( )】函數傳回字串排列方式。
mysql系統資訊函數有:
一、檢視目前MySQL版本號碼
mysql> SELECT VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.22 | +-----------+ 1 row in set (0.00 sec)
相關學習推薦:mysql影片教學
#二、查看目前使用者的連線數
mysql> SELECT CONNECTION_ID(); +-----------------+ | CONNECTION_ID() | +-----------------+ | 2 | +-----------------+ 1 row in set (0.00 sec)
三、使用SHOW PROCESSLIST
指令輸出目前使用者的連線資訊
mysql> SHOW PROCESSLIST; +----+------+------+------+---------+------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+------+------+---------+------+----------+------------------+ | 2 | root | | test | Query | 0 | starting | SHOW PROCESSLIST | +----+------+------+------+---------+------+----------+------------------+ 1 row in set (0.00 sec)
四、檢視目前使用的資料庫
mysql> SELECT DATABASE(),SCHEMA(); +------------+----------+ | DATABASE() | SCHEMA() | +------------+----------+ | test | test | +------------+----------+ 1 row in set (0.00 sec)
五、取得目前登入使用者名稱
mysql> SELECT USER(), CURRENT_USER(), SYSTEM_USER(); +--------+-----------------------------------+---------------+ | USER() | CURRENT_USER() | SYSTEM_USER() | +--------+-----------------------------------+---------------+ | root@ | skip-grants user@skip-grants host | root@ | +--------+-----------------------------------+---------------+ 1 row in set (0.00 sec)
六、 使用CHARSET()
函數傳回字串所使用的字元集
SELECT CHARSET('abc'), CHARSET(CONVERT('abc' USING latin1)), CHARSET(VERSION()); +----------------+--------------------------------------+--------------------+ | CHARSET('abc') | CHARSET(CONVERT('abc' USING latin1)) | CHARSET(VERSION()) | +----------------+--------------------------------------+--------------------+ | utf8 | latin1 | utf8 | +----------------+--------------------------------------+--------------------+ 1 row in set (0.00 sec)
七、使用COLLATION()
函數傳回字串排列方式
mysql> SELECT COLLATION('abc'),COLLATION(CONVERT('abc' USING utf8)); +------------------+--------------------------------------+ | COLLATION('abc') | COLLATION(CONVERT('abc' USING utf8)) | +------------------+--------------------------------------+ | utf8_general_ci | utf8_general_ci | +------------------+--------------------------------------+ 1 row in set (0.00 sec)
八、使用SELECT LAST_INSERT_ID
查看最後一個自動產生的列值
1、一次插入一筆記錄
(1)、先建立表格worker,其Id欄位帶有AUTO_INCREMENT
約束
CREATE TABLE worker (Id INT AUTO_INCREMENT NOT NULL PRIMARY KEY, Name VARCHAR(30)); Query OK, 0 rows affected (0.23 sec)
(2)、分別單獨向表格worker中插入2筆記錄:
mysql> INSERT INTO worker VALUES(NULL, 'jimy'); Query OK, 1 row affected (0.03 sec) mysql> INSERT INTO worker VALUES(NULL, 'Tom'); Query OK, 1 row affected (0.02 sec) mysql> SELECT * FROM worker; +----+------+ | Id | Name | +----+------+ | 1 | jimy | | 2 | Tom | +----+------+ 2 rows in set (0.00 sec)
(3)、檢視已插入的資料可以發現,最後一筆插入的記錄的Id欄位值為2,使用LAST_INSERT_ID()
查看最後自動產生的Id值:
mysql> SELECT LAST_INSERT_ID(); +------------------+ | LAST_INSERT_ID() | +------------------+ | 2 | +------------------+ 1 row in set (0.01 sec)
2、一次同時插入多筆記錄
(1)、接下來,在表格中插入多筆記錄
INSERT INTO worker VALUES (NULL, 'Kevin'),(NULL,'Michal'),(NULL,'Nick'); Query OK, 3 rows affected (0.03 sec) Records: 3 Duplicates: 0 Warnings: 0
(2)、查詢已插入的的記錄,
mysql> SELECT * FROM worker; +----+--------+ | Id | Name | +----+--------+ | 1 | jimy | | 2 | Tom | | 3 | Kevin | | 4 | Michal | | 5 | Nick | +----+--------+ 5 rows in set (0.00 sec) mysql> SELECT LAST_INSERT_ID(); +------------------+ | LAST_INSERT_ID() | +------------------+ | 3 | +------------------+ 1 row in set (0.00 sec)
以上是mysql系統資訊函數有哪些?的詳細內容。更多資訊請關注PHP中文網其他相關文章!