這篇文章主要介紹“MySQL查詢?nèi)罩镜拿睢?,在日常操作中,相信很多人在mysql查詢?nèi)罩镜拿顔栴}上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”mysql查詢?nèi)罩镜拿睢钡囊苫笥兴鶐椭?!接下來,?qǐng)跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷推廣、網(wǎng)站重做改版、驛城網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5開發(fā)、購物商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為驛城等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
mysql查詢?nèi)罩臼怯脕碛涗浻脩舻卿洈?shù)據(jù)庫、記錄用戶在數(shù)據(jù)庫操作的日志。類似oracle的審計(jì)功能,但是出于線上數(shù)據(jù)庫頻繁的操作,會(huì)產(chǎn)生大量的IO和磁盤空間的壓力,mysql是默認(rèn)關(guān)閉的。但是有時(shí)候出于安全的考慮需要開啟,這就要在安全和效率之間權(quán)衡了。
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name | Value |
+------------------+----------------------------------------+
| general_log | OFF | --關(guān)閉狀態(tài)
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log | --查詢?nèi)罩久Q
+------------------+----------------------------------------+
2 rows in set (0.00 sec)
mysql>set global general_log=on;
mysql> show global variables like '%general_log%';
+------------------+----------------------------------------+
| Variable_name | Value |
+------------------+----------------------------------------+
| general_log | ON | --開啟狀態(tài)
| general_log_file | /data/DB/mysql/trcloud-gtt-test-db.log | --查詢?nèi)罩久Q
+------------------+----------------------------------------+
現(xiàn)在來看看這些查詢?nèi)罩径加心男┬畔?br/>登錄數(shù)據(jù)庫進(jìn)行一番操作
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h272.30.249.154 -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'172.30.248.18' (using password: YES) --- 登錄失敗
[root@trcloud-wujian-test01 mysql]# mysql -P3306 -h272.30.249.154 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 191
Server version: 5.6.27-76.0-log Percona Server (GPL), Release 76.0, Revision 5498987
Copyright (c) 2009-2015 Percona LLC and/or its affiliates
Copyright (c) 2000, 2015, 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 test; -- 選擇數(shù)據(jù)庫
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> select * from emp; --查詢
+------+------+
| id | name |
+------+------+
| 1 | jx |
+------+------+
1 row in set (0.00 sec)
mysql> drop table emp; -- 刪除
Query OK, 0 rows affected (0.04 sec)
mysql> ^CCtrl-C -- exit! --退出
Aborted
[root@trcloud-wujian-test01 mysql]
打開查詢?nèi)罩?br/>[root@trcloud-gtt-test-db mysql]# tail -50f trcloud-gtt-test-db.log
160412 14:18:45 190 Connect root@172.30.248.18 on --從哪個(gè)IP用什么用戶登錄失敗記錄
190 Connect Access denied for user 'root'@'172.30.248.18' (using password: YES)
160412 14:19:12 191 Connect root@172.30.248.18 on --記錄從哪個(gè)IP哪個(gè)用戶何時(shí)登錄,191是一個(gè)session的唯一表示,同一個(gè)session這個(gè)數(shù)字是一致的
191 Query select @@version_comment limit 1
160412 14:19:24 191 Query SELECT DATABASE()
191 Init DB test
191 Query show databases
191 Query show tables
191 Field List emp
160412 14:19:33 191 Query select * from emp --查詢操作
160412 14:19:40 191 Query drop table emp --刪除操作
160412 14:20:18 191 Quit --退出session
到此,關(guān)于“mysql查詢?nèi)罩镜拿睢钡膶W(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!