MySQL初始化以及客戶端工具的使用
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
一.什么是關系型數據庫
關系型數據庫通常是把所有的數據都組織成二維關系。之所以稱為關系型數據庫是因為他把數據組織在一個有字段和記錄組成的二維關系表當中。並且在這個關系表之外提供了很多輔助性的工具以完成關系表中的關系的維持及數據訪問等功能。
我們知道如果將數據存儲為字符形式的時候有文本對象和二進制大對象。二進制大對象不會直接存儲在數據庫中,而是放在服務器的某一個路徑上,而在數據庫存儲的知識該數據的指針。比如,存取一張高清壁紙,它不會將這個圖片的內容直接寫入數據庫,而是將這個圖片的絕對路徑存放在數據庫中的某一個字段內。這種關系我們稱之為面向對象的關系型數據庫。(RDBMS)。而現在很多關系型數據庫還支持直接將xml格式的接口進行交互。
二.關系型數據庫的分支
在90年代初,關系型數據庫由Sybase,Informix,Oracle三家公司三足鼎立。這三家公司對公司的規划不同,Sybase和Informix的規划都是很有前瞻性的,而Oracle的目標很有精確,就是把它們的產品做好,最后Oracle不斷地進行完善,很顯然,走到最靠前的當然是Oracle。其中Sybase曾經是和Microsoft公司合作,當時處於某種原因Sybase退出和Microsoft公司的合作,最后Microsoft公司自己研發了SQL Server數據庫,Informix公司則被IBM公司收購,現在Informix只是IBM的一個子項目公司,典型的數據庫代表就是DB2。
早期MySQL是ab公司的,最后以10美元賣給了sun公司,不幸的是sun公司被Oracle公司收購了,而Oracle慣用的伎倆就是將競爭對手買下來再打入冷宮。所以在資本主義面前談理想都是道德主義。sun公司被收購之后,MySQL也就歸Oracle公司啦。Oracle和人們預想的一樣,雖然在收購的時候承諾了5年之內不下手,但事實上在這期間MySQL以及被蹂躪了無數遍啦。所以像之前谷歌,Facebook等公司也從MySQL軟件轉向其他軟件啦。而且在RHEL7版本的默認數據庫已經將MySQL換成了MariaDB。
MySQL的原作者在sum公司被收購之后久另立門戶了,在早起的MySQL的基礎上提出了另外的一個分支叫MariaDB。事實上MariaDB在能夠兼容mysql的基礎上還整合了開源社區中的很強大的技術力量。我們知道mysql早起整合進來的存儲引擎有一個是innodb,而innodb是屬於innobase公司的,innobase公司早在2008年被Oracle收購啦。有幸的是在開源界總是不乏奇人的,比如說著名的percona公司,它是致力於mysql的優化方面已經取得了不菲成績的一個組織,這個組織在早起的改進開源的innodb基礎之上研發了增強版的innodb,命名為xtradb。如你所料,MariaDB的存儲引擎就是用的xtradb。我們可以理解為MariaDB是MySQL進化之后的一個產品。google和Facebook等著名的世界互聯網公司都很看好MariaDB並已經開始使用該軟件啦。
其實google和Facebook還有其他的幾家公司在早起的MySQL的技術理念的不同他們也開發了另一個互聯網產品叫做webscaledb,專門為web而生的一個數據庫系統。它柔和了MySQL,MariaDB,percona和innobase四家公司的技術的產品。
在開源的數據庫產品中還有一個重要的產品叫做PostgreSQL(簡稱pgsql),事實上,早起名字叫做egresql,只是egresql在商業運作上跟Oracle競爭時完全敗下陣來。以至於它銷聲匿跡的比Informix還要早。而事實上就關系型數據庫來講,pgsql在技術上要優秀的多。不過市場決定一切,因此MySQL可能是大家接觸比較多的關系型數據庫。
指定一提的另外一個關系型數據庫叫做sqlite,它和mysql不一樣,我們知道mysql是基於c/s架構,客戶端和服務端是通過mysql協議進行通信的。而sqlite是一個簡單,工作在本地,非服務化的一個API的關系型數據庫接口(它的客戶端和服務端是一體的)。注意,sqlite僅是一個引擎,sqlite主要用在嵌入式平台上又不得不用關系型數據庫接口的這樣的應用場景。再次強調一下,sqlite是一個非C./S架構,它純粹是一個引擎API機制,背后的數據任然存儲為文件系統上的簡單文件,不做過多解析,但完全可以支持我們的程序員使用select,insert等機制對數據完成持久化。
三.MySQL的初始化
我們知道MySQL的安裝方式有很多種,比如rpm,yum,源碼安裝,二進制方式安裝MySQL等等。但是無論哪種方式安裝的MySQL我們都需要做一個操作就是MySQL的初始化。而正確的初始化姿勢我們分為兩個操作。第一,提供配置文件;第二,刪除匿名用戶等等。
1.提供配置文件
相比之前接觸過MySQL的童鞋都知道,MySQL默認的配置文件都是以“*.cnf”結尾的文件,它是集中式的配置文件,多個應用程序共用的配置文件。當然,也可以不這樣玩,后期我會分享案例給大家。我們通過一條命令就可以查看MySQL的一些默認信息。即“[root@yinzhengjie ~]# mysql --help --verbose ”沒錯,通過這個命令我們就可以或得很多輸出:
A>.顯示mysqld程序啟動時可用的選項,通常都是長選項;
B>.顯示mysqld的配置文件中可用的服務變量;
C>.顯示使用配置文件的方式,即:第一,它依次查找每個需要查找的文件,結果是所有文件並集;第二,如果某參數在多個文件中出現多次,后讀取的最終生效。
2.重置用戶信息
大家知道在一個新安裝的服務器上有很多默認的用戶,比如root以及一些匿名用戶,他們都是沒有密碼的,這樣是很不安全的,因此我們需要刪除不必要的用戶,以及給我們需要使用的用戶設置密碼以及授權操作。 我們知道MySQL用戶名賬號由兩部分組成,即用戶名和主機名(username@host),其中“host”還可以使用通配符。如 “%”表示任意長度的任意字符,“_”表示匹配任意單個字符。
A.刪除匿名用戶
1 mysql> select user,host,password from user; 2 +-------------+-------------+-------------------------------------------+ 3 | user | host | password | 4 +-------------+-------------+-------------------------------------------+ 5 | root | localhost | | 6 | root | yinzhengjie | | 7 | root | 127.0.0.1 | | 8 | | localhost | | 9 | | yinzhengjie | | 10 | yinzhengjie | 10.%.%.% | *C260A4F79FA905AF65142FFE0B9A14FE0E1519CC | 11 +-------------+-------------+-------------------------------------------+ 12 6 rows in set (0.00 sec) 13 14 mysql> 15 mysql> 16 mysql> 17 mysql> 18 mysql> drop user ""@localhost; 19 Query OK, 0 rows affected (0.01 sec) 20 21 mysql> drop user ""@yinzhengjie; 22 Query OK, 0 rows affected (0.00 sec) 23 24 mysql> select user,host,password from user; 25 +-------------+-------------+-------------------------------------------+ 26 | user | host | password | 27 +-------------+-------------+-------------------------------------------+ 28 | root | localhost | | 29 | root | yinzhengjie | | 30 | root | 127.0.0.1 | | 31 | yinzhengjie | 10.%.%.% | *C260A4F79FA905AF65142FFE0B9A14FE0E1519CC | 32 +-------------+-------------+-------------------------------------------+ 33 4 rows in set (0.00 sec) 34 35 mysql>
B.給所有的root用戶設置密碼
1 第一種方式: 2 mysql > set password for username@host = password( 'your_password'); 3 第二種方法 4 mysql > update user set password = password('your_password') where user = 'root'; 5 mysql > flush peivileges; 6 第三種方式: 7 [root@yinzhengjie ~]#mysqladmin -u UserName -h Host password 'new_password' -p 8 [root@yinzhengjie ~]#mysqladmin -u UserName -h Host -p flush-privileges
四.連入MySQL服務器
1.MySQL協議
MySQL的客戶端有很多種,不論是那種MySQL客戶端連接mysqld服務器,都是需要使用mysql protocol協議。
2.MySQL接收連接請求
本地通信:
客戶端與服務器端位於同一主機,而且還要基於127.0.0.1(localhost)地址或lo接口進行通信。Linux或是Unix操作系統則是通過Unix Sock,/tmp/mysql.scok,/var/lib/mysql/mysql.sock這些本地文件進行進程間的通信。Widows則是通過memory(共享內存) pipe(命名管道)的方式進行通信的。
遠程通信:
客戶端與服務器位於不同的主機,或在統一主機便使用非回環地址通信。而遠程通信時,通常是基於套接字通信,即TCP Socket。
3.MySQL客戶端工具
事實上MySQL的客戶端工具有很多種,可不止mysql這一種喲(只不過mysql這個客戶端時最著名的一個)。其他著名的客戶端工具還有:mysqladmin,mysqldump,mysqlcheck等等。
客戶端([client])通信的選項:
指定用戶 : -u,--user=
指定主機名 : -h, --host=
指定密碼 : -p, --password=
指定協議 : --protocol={tcp|socket|memory|pipe}
指定端口 : --port= #MySQL默認是3306端口
指定套接字 : --socket= # 例如:/tmp/mysql.sock
非客戶端類的管理工具:myisamchk(監測工具)和myisampack(打包工具)。
4.mysql命令行選項
壓縮傳輸 : -compress
字符集 : --default-character-set
顯示版本號 : -V:
顯示詳細信息 : -v:
指定ca證書 : --ssl-ca
ca證書的文件夾: --ssl-capath (一般有多個CA證書,就可以指定一個目錄)
客戶端證書 : --ssl-cert
加密方式 : --ssl-cipher
使用的私鑰 : --ssl-key
驗證服務器端證書: --ssl-verify-server-cert
指定要使用的數據庫:--database= -D
輸出結果為html格式的文檔::-H --html
輸出結果為xml格式的文檔: -X --xml:
發送命令時拒絕使用無where字句的uodate或delete命令: --safe-updates
5.mysql命令提示符
mysql> ---->等待輸入命令
'> ---->前面提供的‘未提供結束’,接下來那兩行一樣的道理。
”>
`>
—> ---->續航提示符
/*> ---->注釋信息(結束就用戶"*/",比如:/*yinzhengjie*>)
6.mysql的命令行編輯快捷鍵
ctrl+w:刪除光標所在處之前的一個單詞
ctrl+u:刪除光標之前至行首的所有內容,並將其保存在緩存(buffer)當中。
ctrl+y:粘貼之前ctrl+w或ctrl+u刪除的內容
ctrl+a:移動光標至行首
ctrl+e:移動光標至行尾
五.mysqladmin工具用法詳解
mysqladmin可以讓用戶不進入mysql的交互界面,直接在命令行就可以運行SQL語句啦。命令格式:“mysqladmin [options] command [arg] [command[arg]] .....”,接下來,讓我們一起研究一下mysqladmin的用法。這個命令其實很有用,尤其是你在寫shell腳本的時候,操作數據的時候它的用法就可以大展身手了。
1.創建空數據庫
1 [root@yinzhengjie ~]# mysqladmin create yinzhengjiedb #創建一個叫yinzhengjiedb的數據庫。 2 [root@yinzhengjie ~]# mysql -e 'show databases;' #我們可以用mysql的-e選項來進行驗證是否創建成功、 3 +--------------------+ 4 | Database | 5 +--------------------+ 6 | information_schema | 7 | mysql | 8 | test | 9 | yinzhengjie | 10 | yinzhengjiedb | 11 +--------------------+ 12 [root@yinzhengjie ~]#
2.刪除數據庫
1 [root@yinzhengjie ~]# mysql -e 'show databases;' 2 +--------------------+ 3 | Database | 4 +--------------------+ 5 | information_schema | 6 | mysql | 7 | test | 8 | yinzhengjie | 9 | yinzhengjiedb | 10 +--------------------+ 11 [root@yinzhengjie ~]# mysqladmin drop yinzhengjiedb 12 Dropping the database is potentially a very bad thing to do. 13 Any data stored in the database will be destroyed. 14 15 Do you really want to drop the 'yinzhengjiedb' database [y/N] y #此處我們需要交互式輸入一個y。 16 Database "yinzhengjiedb" dropped 17 [root@yinzhengjie ~]# mysql -e 'show databases;' 18 +--------------------+ 19 | Database | 20 +--------------------+ 21 | information_schema | 22 | mysql | 23 | test | 24 | yinzhengjie | 25 +--------------------+ 26 [root@yinzhengjie ~]#
3.輸出MySQL簡要狀態信息
1 [root@yinzhengjie ~]# mysqladmin status #輸出簡要狀態信息 2 Uptime: 232451 Threads: 1 Questions: 228 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 3 [root@yinzhengjie ~]# 4 [root@yinzhengjie ~]# mysqladmin status --sleep 1 --count 5 #表示每個1秒刷新一次,總共打印5次 5 Uptime: 232465 Threads: 1 Questions: 229 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 6 Uptime: 232466 Threads: 1 Questions: 229 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 7 Uptime: 232467 Threads: 1 Questions: 229 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 8 Uptime: 232468 Threads: 1 Questions: 229 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 9 Uptime: 232469 Threads: 1 Questions: 229 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 10 [root@yinzhengjie ~]# 11 [root@yinzhengjie ~]# 12 [root@yinzhengjie ~]# mysqladmin status --sleep 1 #表示每秒刷新一次,可以安裝Ctrl+C 結束 13 Uptime: 232474 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 14 Uptime: 232475 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 15 Uptime: 232476 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 16 Uptime: 232477 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 17 Uptime: 232478 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 18 Uptime: 232479 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 19 Uptime: 232480 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 20 Uptime: 232481 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 21 Uptime: 232482 Threads: 1 Questions: 230 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 34 Queries per second avg: 0.0 22 ^C[root@yinzhengjie ~]#
4.debug 調試信息用法展示
1 [root@yinzhengjie ~]# more /var/log/mysqld.log 2 [root@yinzhengjie ~]# 3 [root@yinzhengjie ~]# mysqladmin debug 4 [root@yinzhengjie ~]# more /var/log/mysqld.log 5 6 Memory status: 7 Non-mmapped space allocated from system: 6066176 8 Number of free chunks: 12 9 Number of fastbin blocks: 0 10 Number of mmapped regions: 11 11 Space in mmapped regions: 23597056 12 Maximum total allocated space: 0 13 Space available in freed fastbin blocks: 0 14 Total allocated space: 6010288 15 Total free space: 55888 16 Top-most, releasable space: 45424 17 Estimated memory (with thread stack): 29925376 18 19 20 21 Events status: 22 LLA = Last Locked At LUA = Last Unlocked At 23 WOC = Waiting On Condition DL = Data Locked 24 25 Event scheduler status: 26 State : INITIALIZED 27 Thread id : 0 28 LLA : n/a:0 29 LUA : n/a:0 30 WOC : NO 31 Workers : 0 32 Executed : 0 33 Data locked: NO 34 35 Event queue status: 36 Element count : 0 37 Data locked : NO 38 Attempting lock : NO 39 LLA : drop_schema_events:375 40 LUA : drop_schema_events:377 41 WOC : NO 42 Next activation : never 43 44 Status information: 45 46 Current dir: /var/lib/mysql/ 47 Running threads: 1 Stack size: 262144 48 Current locks: 49 lock: 0x7f7740089338: 50 51 lock: 0x7f7740086ee8: 52 53 lock: 0x7f77400847b8: 54 55 lock: 0x7f77400823f8: 56 57 lock: 0x7f7740080488: 58 59 lock: 0x7f774007f398: 60 61 lock: 0x7f7740072028: 62 63 lock: 0x7f774006ba58: 64 65 lock: 0x7f7740069368: 66 67 lock: 0x7f7740065678: 68 69 lock: 0x7f7740061a98: 70 71 lock: 0x7f774005ede8: 72 73 lock: 0x7f774005b838: 74 75 lock: 0x7f77400595c8: 76 77 lock: 0x7f774004ed08: 78 79 lock: 0x7f774004a758: 80 81 lock: 0x7f7740044c38: 82 83 lock: 0x7f77400400b8: 84 85 lock: 0x7f77400377c8: 86 87 lock: 0x7f7740031ed8: 88 89 lock: 0x7f7740029c08: 90 91 lock: 0x7f7740027cf8: 92 93 lock: 0x7f7740024308: 94 95 lock: 0x7f774001e728: 96 97 lock: 0x7f77400158e8: 98 99 lock: 0x7f774000ceb8: 100 101 lock: 0x291f5f8: 102 103 lock: 0x29148c8: 104 105 lock: 0x2909d28: 106 107 lock: 0x2900de8: 108 109 lock: 0x28f65f8: 110 111 lock: 0x28e6f58: 112 113 lock: 0x28e1098: 114 115 lock: 0x28d93f8: 116 117 118 Key caches: 119 default 120 Buffer_size: 8384512 121 Block_size: 1024 122 Division_limit: 100 123 Age_limit: 300 124 blocks used: 13 125 not flushed: 0 126 w_requests: 4 127 writes: 2 128 r_requests: 284 129 reads: 13 130 131 132 handler status: 133 read_key: 80 134 read_next: 126 135 read_rnd 126 136 read_first: 80 137 write: 70 138 delete 2 139 update: 0 140 141 Table status: 142 Opened tables: 41 143 Open tables: 34 144 Open files: 68 145 Open streams: 0 146 147 Alarm status: 148 Active alarms: 0 149 Max used alarms: 1 150 Next alarm time: 0 151 152 Begin safemalloc memory dump: 153 154 End safemalloc memory dump. 155 [root@yinzhengjie ~]#
5.extended-status用法展示
1 [root@yinzhengjie ~]# mysqladmin extended-status 2 +-----------------------------------+----------+ 3 | Variable_name | Value | 4 +-----------------------------------+----------+ 5 | Aborted_clients | 0 | 6 | Aborted_connects | 0 | 7 | Binlog_cache_disk_use | 0 | 8 | Binlog_cache_use | 0 | 9 | Bytes_received | 19009 | 10 | Bytes_sent | 200183 | 11 | Com_admin_commands | 3 | 12 | Com_assign_to_keycache | 0 | 13 | Com_alter_db | 0 | 14 | Com_alter_db_upgrade | 0 | 15 | Com_alter_event | 0 | 16 | Com_alter_function | 0 | 17 | Com_alter_procedure | 0 | 18 | Com_alter_server | 0 | 19 | Com_alter_table | 0 | 20 | Com_alter_tablespace | 0 | 21 | Com_analyze | 0 | 22 | Com_backup_table | 0 | 23 | Com_begin | 0 | 24 | Com_binlog | 0 | 25 | Com_call_procedure | 0 | 26 | Com_change_db | 10 | 27 | Com_change_master | 0 | 28 | Com_check | 0 | 29 | Com_checksum | 0 | 30 | Com_commit | 0 | 31 | Com_create_db | 1 | 32 | Com_create_event | 0 | 33 | Com_create_function | 0 | 34 | Com_create_index | 0 | 35 | Com_create_procedure | 0 | 36 | Com_create_server | 0 | 37 | Com_create_table | 0 | 38 | Com_create_trigger | 0 | 39 | Com_create_udf | 0 | 40 | Com_create_user | 0 | 41 | Com_create_view | 0 | 42 | Com_dealloc_sql | 0 | 43 | Com_delete | 0 | 44 | Com_delete_multi | 0 | 45 | Com_do | 0 | 46 | Com_drop_db | 1 | 47 | Com_drop_event | 0 | 48 | Com_drop_function | 0 | 49 | Com_drop_index | 0 | 50 | Com_drop_procedure | 0 | 51 | Com_drop_server | 0 | 52 | Com_drop_table | 0 | 53 | Com_drop_trigger | 0 | 54 | Com_drop_user | 2 | 55 | Com_drop_view | 0 | 56 | Com_empty_query | 0 | 57 | Com_execute_sql | 0 | 58 | Com_flush | 0 | 59 | Com_grant | 0 | 60 | Com_ha_close | 0 | 61 | Com_ha_open | 0 | 62 | Com_ha_read | 0 | 63 | Com_help | 0 | 64 | Com_insert | 0 | 65 | Com_insert_select | 0 | 66 | Com_install_plugin | 0 | 67 | Com_kill | 0 | 68 | Com_load | 0 | 69 | Com_load_master_data | 0 | 70 | Com_load_master_table | 0 | 71 | Com_lock_tables | 0 | 72 | Com_optimize | 0 | 73 | Com_preload_keys | 0 | 74 | Com_prepare_sql | 0 | 75 | Com_purge | 0 | 76 | Com_purge_before_date | 0 | 77 | Com_release_savepoint | 0 | 78 | Com_rename_table | 0 | 79 | Com_rename_user | 0 | 80 | Com_repair | 0 | 81 | Com_replace | 0 | 82 | Com_replace_select | 0 | 83 | Com_reset | 0 | 84 | Com_restore_table | 0 | 85 | Com_revoke | 0 | 86 | Com_revoke_all | 0 | 87 | Com_rollback | 0 | 88 | Com_rollback_to_savepoint | 0 | 89 | Com_savepoint | 0 | 90 | Com_select | 148 | 91 | Com_set_option | 21 | 92 | Com_show_authors | 0 | 93 | Com_show_binlog_events | 0 | 94 | Com_show_binlogs | 0 | 95 | Com_show_charsets | 0 | 96 | Com_show_collations | 0 | 97 | Com_show_column_types | 0 | 98 | Com_show_contributors | 0 | 99 | Com_show_create_db | 0 | 100 | Com_show_create_event | 0 | 101 | Com_show_create_func | 0 | 102 | Com_show_create_proc | 0 | 103 | Com_show_create_table | 0 | 104 | Com_show_create_trigger | 0 | 105 | Com_show_databases | 4 | 106 | Com_show_engine_logs | 0 | 107 | Com_show_engine_mutex | 0 | 108 | Com_show_engine_status | 0 | 109 | Com_show_events | 0 | 110 | Com_show_errors | 0 | 111 | Com_show_fields | 23 | 112 | Com_show_function_status | 0 | 113 | Com_show_grants | 0 | 114 | Com_show_keys | 0 | 115 | Com_show_master_status | 0 | 116 | Com_show_new_master | 0 | 117 | Com_show_open_tables | 0 | 118 | Com_show_plugins | 0 | 119 | Com_show_privileges | 0 | 120 | Com_show_procedure_status | 0 | 121 | Com_show_processlist | 0 | 122 | Com_show_profile | 0 | 123 | Com_show_profiles | 0 | 124 | Com_show_slave_hosts | 0 | 125 | Com_show_slave_status | 0 | 126 | Com_show_status | 23 | 127 | Com_show_storage_engines | 0 | 128 | Com_show_table_status | 0 | 129 | Com_show_tables | 2 | 130 | Com_show_triggers | 0 | 131 | Com_show_variables | 0 | 132 | Com_show_warnings | 0 | 133 | Com_slave_start | 0 | 134 | Com_slave_stop | 0 | 135 | Com_stmt_close | 0 | 136 | Com_stmt_execute | 0 | 137 | Com_stmt_fetch | 0 | 138 | Com_stmt_prepare | 0 | 139 | Com_stmt_reprepare | 0 | 140 | Com_stmt_reset | 0 | 141 | Com_stmt_send_long_data | 0 | 142 | Com_truncate | 0 | 143 | Com_uninstall_plugin | 0 | 144 | Com_unlock_tables | 0 | 145 | Com_update | 0 | 146 | Com_update_multi | 0 | 147 | Com_xa_commit | 0 | 148 | Com_xa_end | 0 | 149 | Com_xa_prepare | 0 | 150 | Com_xa_recover | 0 | 151 | Com_xa_rollback | 0 | 152 | Com_xa_start | 0 | 153 | Compression | OFF | 154 | Connections | 22 | 155 | Created_tmp_disk_tables | 0 | 156 | Created_tmp_files | 5 | 157 | Created_tmp_tables | 14 | 158 | Delayed_errors | 0 | 159 | Delayed_insert_threads | 0 | 160 | Delayed_writes | 0 | 161 | Flush_commands | 1 | 162 | Handler_commit | 0 | 163 | Handler_delete | 2 | 164 | Handler_discover | 0 | 165 | Handler_prepare | 0 | 166 | Handler_read_first | 80 | 167 | Handler_read_key | 80 | 168 | Handler_read_next | 126 | 169 | Handler_read_prev | 14 | 170 | Handler_read_rnd | 126 | 171 | Handler_read_rnd_next | 1190 | 172 | Handler_rollback | 0 | 173 | Handler_savepoint | 0 | 174 | Handler_savepoint_rollback | 0 | 175 | Handler_update | 0 | 176 | Handler_write | 70 | 177 | Innodb_buffer_pool_pages_data | 19 | 178 | Innodb_buffer_pool_pages_dirty | 0 | 179 | Innodb_buffer_pool_pages_flushed | 1 | 180 | Innodb_buffer_pool_pages_free | 493 | 181 | Innodb_buffer_pool_pages_misc | 0 | 182 | Innodb_buffer_pool_pages_total | 512 | 183 | Innodb_buffer_pool_read_ahead_rnd | 1 | 184 | Innodb_buffer_pool_read_ahead_seq | 0 | 185 | Innodb_buffer_pool_read_requests | 84 | 186 | Innodb_buffer_pool_reads | 12 | 187 | Innodb_buffer_pool_wait_free | 0 | 188 | Innodb_buffer_pool_write_requests | 1 | 189 | Innodb_data_fsyncs | 7 | 190 | Innodb_data_pending_fsyncs | 0 | 191 | Innodb_data_pending_reads | 0 | 192 | Innodb_data_pending_writes | 0 | 193 | Innodb_data_read | 2494464 | 194 | Innodb_data_reads | 25 | 195 | Innodb_data_writes | 7 | 196 | Innodb_data_written | 35328 | 197 | Innodb_dblwr_pages_written | 1 | 198 | Innodb_dblwr_writes | 1 | 199 | Innodb_log_waits | 0 | 200 | Innodb_log_write_requests | 0 | 201 | Innodb_log_writes | 2 | 202 | Innodb_os_log_fsyncs | 5 | 203 | Innodb_os_log_pending_fsyncs | 0 | 204 | Innodb_os_log_pending_writes | 0 | 205 | Innodb_os_log_written | 1024 | 206 | Innodb_page_size | 16384 | 207 | Innodb_pages_created | 0 | 208 | Innodb_pages_read | 19 | 209 | Innodb_pages_written | 1 | 210 | Innodb_row_lock_current_waits | 0 | 211 | Innodb_row_lock_time | 0 | 212 | Innodb_row_lock_time_avg | 0 | 213 | Innodb_row_lock_time_max | 0 | 214 | Innodb_row_lock_waits | 0 | 215 | Innodb_rows_deleted | 0 | 216 | Innodb_rows_inserted | 0 | 217 | Innodb_rows_read | 0 | 218 | Innodb_rows_updated | 0 | 219 | Key_blocks_not_flushed | 0 | 220 | Key_blocks_unused | 6681 | 221 | Key_blocks_used | 13 | 222 | Key_read_requests | 284 | 223 | Key_reads | 13 | 224 | Key_write_requests | 4 | 225 | Key_writes | 2 | 226 | Last_query_cost | 0.000000 | 227 | Max_used_connections | 1 | 228 | Not_flushed_delayed_rows | 0 | 229 | Open_files | 68 | 230 | Open_streams | 0 | 231 | Open_table_definitions | 34 | 232 | Open_tables | 34 | 233 | Opened_files | 129 | 234 | Opened_table_definitions | 34 | 235 | Opened_tables | 41 | 236 | Prepared_stmt_count | 0 | 237 | Qcache_free_blocks | 0 | 238 | Qcache_free_memory | 0 | 239 | Qcache_hits | 0 | 240 | Qcache_inserts | 0 | 241 | Qcache_lowmem_prunes | 0 | 242 | Qcache_not_cached | 0 | 243 | Qcache_queries_in_cache | 0 | 244 | Qcache_total_blocks | 0 | 245 | Queries | 235 | 246 | Questions | 235 | 247 | Rpl_status | NULL | 248 | Select_full_join | 0 | 249 | Select_full_range_join | 0 | 250 | Select_range | 0 | 251 | Select_range_check | 0 | 252 | Select_scan | 16 | 253 | Slave_open_temp_tables | 0 | 254 | Slave_retried_transactions | 0 | 255 | Slave_running | OFF | 256 | Slow_launch_threads | 0 | 257 | Slow_queries | 0 | 258 | Sort_merge_passes | 0 | 259 | Sort_range | 7 | 260 | Sort_rows | 126 | 261 | Sort_scan | 7 | 262 | Ssl_accept_renegotiates | 0 | 263 | Ssl_accepts | 0 | 264 | Ssl_callback_cache_hits | 0 | 265 | Ssl_cipher | | 266 | Ssl_cipher_list | | 267 | Ssl_client_connects | 0 | 268 | Ssl_connect_renegotiates | 0 | 269 | Ssl_ctx_verify_depth | 0 | 270 | Ssl_ctx_verify_mode | 0 | 271 | Ssl_default_timeout | 0 | 272 | Ssl_finished_accepts | 0 | 273 | Ssl_finished_connects | 0 | 274 | Ssl_session_cache_hits | 0 | 275 | Ssl_session_cache_misses | 0 | 276 | Ssl_session_cache_mode | NONE | 277 | Ssl_session_cache_overflows | 0 | 278 | Ssl_session_cache_size | 0 | 279 | Ssl_session_cache_timeouts | 0 | 280 | Ssl_sessions_reused | 0 | 281 | Ssl_used_session_cache_entries | 0 | 282 | Ssl_verify_depth | 0 | 283 | Ssl_verify_mode | 0 | 284 | Ssl_version | | 285 | Table_locks_immediate | 186 | 286 | Table_locks_waited | 0 | 287 | Tc_log_max_pages_used | 0 | 288 | Tc_log_page_size | 0 | 289 | Tc_log_page_waits | 0 | 290 | Threads_cached | 0 | 291 | Threads_connected | 1 | 292 | Threads_created | 21 | 293 | Threads_running | 1 | 294 | Uptime | 232802 | 295 | Uptime_since_flush_status | 232802 | 296 +-----------------------------------+----------+ 297 [root@yinzhengjie ~]#
6.flush-hosts
1 [root@yinzhengjie ~]# mysqladmin flush-hosts #清空主機相關的緩存:DNS解析緩存,此前因為連接錯誤次數過多而被拒絕訪問mysqld的主機列表 2 [root@yinzhengjie ~]#
7. flush-logs
1 [root@yinzhengjie ~]# mysqladmin flush-logs #日志滾動,主要是二進制日志和中繼日志 2 [root@yinzhengjie ~]#
8.refresh
1 [root@yinzhengjie ~]# mysqladmin refresh #相當於同時使用flush-logs和flush-hosts 2 [root@yinzhengjie ~]#
9.flush-privileges
1 [root@yinzhengjie ~]# mysqladmin flush-privileges #通知服務器重讀授權表 2 [root@yinzhengjie ~]#
10.reload
1 [root@yinzhengjie ~]# mysqladmin reload #重載授權表,相當於flush-privileges 2 [root@yinzhengjie ~]#
11.flush-status
1 [root@yinzhengjie ~]# mysqladmin flush-status #重置狀態變量的值 2 [root@yinzhengjie ~]#
12.flush-tables
1 [root@yinzhengjie ~]# mysqladmin flush-tables #關閉當前打開的表文件句柄 2 [root@yinzhengjie ~]#
13.flush-threads
1 [root@yinzhengjie ~]# mysqladmin flush-threads #清空線程緩存 2 [root@yinzhengjie ~]#
14.kill
1 [root@yinzhengjie ~]# mysqladmin kill #需要輸入線程ID喲 2 mysqladmin: Too few arguments to 'kill' 3 [root@yinzhengjie ~]#
15.processlist
1 [root@yinzhengjie ~]# mysqladmin processlist #線程列表 2 +----+------+-----------+----+---------+------+-------+------------------+ 3 | Id | User | Host | db | Command | Time | State | Info | 4 +----+------+-----------+----+---------+------+-------+------------------+ 5 | 34 | root | localhost | | Query | 0 | | show processlist | 6 +----+------+-----------+----+---------+------+-------+------------------+ 7 [root@yinzhengjie ~]#
16.password
1 [root@yinzhengjie ~]# mysqladmin -u root -h localhost password 'yinzhengjie' -p 2 Enter password: -------->注意,由於我的數據庫一開始是沒有設置密碼的,因此我這里是第一次給我的數據庫設置密碼,這里要求我們輸入以前的密碼我們直接回車即可。 3 [root@yinzhengjie ~]# 4 [root@yinzhengjie ~]# mysqladmin -u root -h localhost -pyinzhengjie flush-privileges #需要刷新一下授權。 5 [root@yinzhengjie ~]# 6 [root@yinzhengjie ~]# mysql -pyinzhengjie #驗證是否可用正常登陸。 7 Welcome to the MySQL monitor. Commands end with ; or \g. 8 Your MySQL connection id is 39 9 Server version: 5.1.73 Source distribution 10 11 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 12 13 Oracle is a registered trademark of Oracle Corporation and/or its 14 affiliates. Other names may be trademarks of their respective 15 owners. 16 17 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 18 19 mysql>
17.ping
1 [root@yinzhengjie ~]# mysqladmin -pyinzhengjie ping #判斷MySQL是否在線。 2 mysqld is alive 3 [root@yinzhengjie ~]#
18.shutdown
1 [root@yinzhengjie ~]# mysqladmin -pyinzhengjie shutdown #關閉mysqld進程 2 [root@yinzhengjie ~]# lsof -i:3306 3 [root@yinzhengjie ~]#
19.start-slave
1 [root@yinzhengjie ~]# 2 [root@yinzhengjie ~]# mysqladmin -pyinzhengjie start-slave #啟動從服務器進程
20.stop-slave
1 [root@yinzhengjie ~]# 2 [root@yinzhengjie ~]# mysqladmin -pyinzhengjie stop-slave #關閉從服務器進程
21.variables
1 [root@yinzhengjie ~]# mysqladmin -pyinzhengjie variables 2 +-----------------------------------------+-------------------------------------------------------------------------------------------+ 3 | Variable_name | Value | 4 +-----------------------------------------+-------------------------------------------------------------------------------------------+ 5 | auto_increment_increment | 1 | 6 | auto_increment_offset | 1 | 7 | autocommit | ON | 8 | automatic_sp_privileges | ON | 9 | back_log | 50 | 10 | basedir | /usr/ | 11 | big_tables | OFF | 12 | binlog_cache_size | 32768 | 13 | binlog_direct_non_transactional_updates | OFF | 14 | binlog_format | STATEMENT | 15 | bulk_insert_buffer_size | 8388608 | 16 | character_set_client | latin1 | 17 | character_set_connection | latin1 | 18 | character_set_database | latin1 | 19 | character_set_filesystem | binary | 20 | character_set_results | latin1 | 21 | character_set_server | latin1 | 22 | character_set_system | utf8 | 23 | character_sets_dir | /usr/share/mysql/charsets/ | 24 | collation_connection | latin1_swedish_ci | 25 | collation_database | latin1_swedish_ci | 26 | collation_server | latin1_swedish_ci | 27 | completion_type | 0 | 28 | concurrent_insert | 1 | 29 | connect_timeout | 10 | 30 | datadir | /var/lib/mysql/ | 31 | date_format | %Y-%m-%d | 32 | datetime_format | %Y-%m-%d %H:%i:%s | 33 | default_week_format | 0 | 34 | delay_key_write | ON | 35 | delayed_insert_limit | 100 | 36 | delayed_insert_timeout | 300 | 37 | delayed_queue_size | 1000 | 38 | div_precision_increment | 4 | 39 | engine_condition_pushdown | ON | 40 | error_count | 0 | 41 | event_scheduler | OFF | 42 | expire_logs_days | 0 | 43 | flush | OFF | 44 | flush_time | 0 | 45 | foreign_key_checks | ON | 46 | ft_boolean_syntax | + -><()~*:""&| | 47 | ft_max_word_len | 84 | 48 | ft_min_word_len | 4 | 49 | ft_query_expansion_limit | 20 | 50 | ft_stopword_file | (built-in) | 51 | general_log | OFF | 52 | general_log_file | /var/run/mysqld/mysqld.log | 53 | group_concat_max_len | 1024 | 54 | have_community_features | YES | 55 | have_compress | YES | 56 | have_crypt | YES | 57 | have_csv | YES | 58 | have_dynamic_loading | YES | 59 | have_geometry | YES | 60 | have_innodb | YES | 61 | have_ndbcluster | NO | 62 | have_openssl | DISABLED | 63 | have_partitioning | YES | 64 | have_query_cache | YES | 65 | have_rtree_keys | YES | 66 | have_ssl | DISABLED | 67 | have_symlink | DISABLED | 68 | hostname | yinzhengjie | 69 | identity | 0 | 70 | ignore_builtin_innodb | OFF | 71 | init_connect | | 72 | init_file | | 73 | init_slave | | 74 | innodb_adaptive_hash_index | ON | 75 | innodb_additional_mem_pool_size | 1048576 | 76 | innodb_autoextend_increment | 8 | 77 | innodb_autoinc_lock_mode | 1 | 78 | innodb_buffer_pool_size | 8388608 | 79 | innodb_checksums | ON | 80 | innodb_commit_concurrency | 0 | 81 | innodb_concurrency_tickets | 500 | 82 | innodb_data_file_path | ibdata1:10M:autoextend | 83 | innodb_data_home_dir | | 84 | innodb_doublewrite | ON | 85 | innodb_fast_shutdown | 1 | 86 | innodb_file_io_threads | 4 | 87 | innodb_file_per_table | OFF | 88 | innodb_flush_log_at_trx_commit | 1 | 89 | innodb_flush_method | | 90 | innodb_force_recovery | 0 | 91 | innodb_lock_wait_timeout | 50 | 92 | innodb_locks_unsafe_for_binlog | OFF | 93 | innodb_log_buffer_size | 1048576 | 94 | innodb_log_file_size | 5242880 | 95 | innodb_log_files_in_group | 2 | 96 | innodb_log_group_home_dir | ./ | 97 | innodb_max_dirty_pages_pct | 90 | 98 | innodb_max_purge_lag | 0 | 99 | innodb_mirrored_log_groups | 1 | 100 | innodb_open_files | 300 | 101 | innodb_rollback_on_timeout | OFF | 102 | innodb_stats_method | nulls_equal | 103 | innodb_stats_on_metadata | ON | 104 | innodb_support_xa | ON | 105 | innodb_sync_spin_loops | 20 | 106 | innodb_table_locks | ON | 107 | innodb_thread_concurrency | 8 | 108 | innodb_thread_sleep_delay | 10000 | 109 | innodb_use_legacy_cardinality_algorithm | ON | 110 | insert_id | 0 | 111 | interactive_timeout | 28800 | 112 | join_buffer_size | 131072 | 113 | keep_files_on_create | OFF | 114 | key_buffer_size | 8384512 | 115 | key_cache_age_threshold | 300 | 116 | key_cache_block_size | 1024 | 117 | key_cache_division_limit | 100 | 118 | language | /usr/share/mysql/english/ | 119 | large_files_support | ON | 120 | large_page_size | 0 | 121 | large_pages | OFF | 122 | last_insert_id | 0 | 123 | lc_time_names | en_US | 124 | license | GPL | 125 | local_infile | ON | 126 | locked_in_memory | OFF | 127 | log | OFF | 128 | log_bin | OFF | 129 | log_bin_trust_function_creators | OFF | 130 | log_bin_trust_routine_creators | OFF | 131 | log_error | /var/log/mysqld.log | 132 | log_output | FILE | 133 | log_queries_not_using_indexes | OFF | 134 | log_slave_updates | OFF | 135 | log_slow_queries | OFF | 136 | log_warnings | 1 | 137 | long_query_time | 10.000000 | 138 | low_priority_updates | OFF | 139 | lower_case_file_system | OFF | 140 | lower_case_table_names | 0 | 141 | max_allowed_packet | 1048576 | 142 | max_binlog_cache_size | 18446744073709547520 | 143 | max_binlog_size | 1073741824 | 144 | max_connect_errors | 10 | 145 | max_connections | 151 | 146 | max_delayed_threads | 20 | 147 | max_error_count | 64 | 148 | max_heap_table_size | 16777216 | 149 | max_insert_delayed_threads | 20 | 150 | max_join_size | 18446744073709551615 | 151 | max_length_for_sort_data | 1024 | 152 | max_long_data_size | 1048576 | 153 | max_prepared_stmt_count | 16382 | 154 | max_relay_log_size | 0 | 155 | max_seeks_for_key | 18446744073709551615 | 156 | max_sort_length | 1024 | 157 | max_sp_recursion_depth | 0 | 158 | max_tmp_tables | 32 | 159 | max_user_connections | 0 | 160 | max_write_lock_count | 18446744073709551615 | 161 | min_examined_row_limit | 0 | 162 | multi_range_count | 256 | 163 | myisam_data_pointer_size | 6 | 164 | myisam_max_sort_file_size | 9223372036853727232 | 165 | myisam_mmap_size | 18446744073709551615 | 166 | myisam_recover_options | OFF | 167 | myisam_repair_threads | 1 | 168 | myisam_sort_buffer_size | 8388608 | 169 | myisam_stats_method | nulls_unequal | 170 | myisam_use_mmap | OFF | 171 | net_buffer_length | 16384 | 172 | net_read_timeout | 30 | 173 | net_retry_count | 10 | 174 | net_write_timeout | 60 | 175 | new | OFF | 176 | old | OFF | 177 | old_alter_table | OFF | 178 | old_passwords | OFF | 179 | open_files_limit | 1024 | 180 | optimizer_prune_level | 1 | 181 | optimizer_search_depth | 62 | 182 | optimizer_switch | index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on | 183 | pid_file | /var/run/mysqld/mysqld.pid | 184 | plugin_dir | /usr/lib64/mysql/plugin | 185 | port | 3306 | 186 | preload_buffer_size | 32768 | 187 | profiling | OFF | 188 | profiling_history_size | 15 | 189 | protocol_version | 10 | 190 | pseudo_thread_id | 0 | 191 | query_alloc_block_size | 8192 | 192 | query_cache_limit | 1048576 | 193 | query_cache_min_res_unit | 4096 | 194 | query_cache_size | 0 | 195 | query_cache_type | ON | 196 | query_cache_wlock_invalidate | OFF | 197 | query_prealloc_size | 8192 | 198 | rand_seed1 | | 199 | rand_seed2 | | 200 | range_alloc_block_size | 4096 | 201 | read_buffer_size | 131072 | 202 | read_only | OFF | 203 | read_rnd_buffer_size | 262144 | 204 | relay_log | | 205 | relay_log_index | | 206 | relay_log_info_file | relay-log.info | 207 | relay_log_purge | ON | 208 | relay_log_space_limit | 0 | 209 | report_host | | 210 | report_password | | 211 | report_port | 3306 | 212 | report_user | | 213 | rpl_recovery_rank | 0 | 214 | secure_auth | OFF | 215 | secure_file_priv | | 216 | server_id | 0 | 217 | skip_external_locking | ON | 218 | skip_name_resolve | OFF | 219 | skip_networking | OFF | 220 | skip_show_database | OFF | 221 | slave_compressed_protocol | OFF | 222 | slave_exec_mode | STRICT | 223 | slave_load_tmpdir | /tmp | 224 | slave_max_allowed_packet | 1073741824 | 225 | slave_net_timeout | 3600 | 226 | slave_skip_errors | OFF | 227 | slave_transaction_retries | 10 | 228 | slow_launch_time | 2 | 229 | slow_query_log | OFF | 230 | slow_query_log_file | /var/run/mysqld/mysqld-slow.log | 231 | socket | /var/lib/mysql/mysql.sock | 232 | sort_buffer_size | 2097144 | 233 | sql_auto_is_null | ON | 234 | sql_big_selects | ON | 235 | sql_big_tables | OFF | 236 | sql_buffer_result | OFF | 237 | sql_log_bin | ON | 238 | sql_log_off | OFF | 239 | sql_log_update | ON | 240 | sql_low_priority_updates | OFF | 241 | sql_max_join_size | 18446744073709551615 | 242 | sql_mode | | 243 | sql_notes | ON | 244 | sql_quote_show_create | ON | 245 | sql_safe_updates | OFF | 246 | sql_select_limit | 18446744073709551615 | 247 | sql_slave_skip_counter | | 248 | sql_warnings | OFF | 249 | ssl_ca | | 250 | ssl_capath | | 251 | ssl_cert | | 252 | ssl_cipher | | 253 | ssl_key | | 254 | storage_engine | MyISAM | 255 | sync_binlog | 0 | 256 | sync_frm | ON | 257 | system_time_zone | PST | 258 | table_definition_cache | 256 | 259 | table_lock_wait_timeout | 50 | 260 | table_open_cache | 64 | 261 | table_type | MyISAM | 262 | thread_cache_size | 0 | 263 | thread_handling | one-thread-per-connection | 264 | thread_stack | 262144 | 265 | time_format | %H:%i:%s | 266 | time_zone | SYSTEM | 267 | timed_mutexes | OFF | 268 | timestamp | 1510669162 | 269 | tmp_table_size | 16777216 | 270 | tmpdir | /tmp | 271 | transaction_alloc_block_size | 8192 | 272 | transaction_prealloc_size | 4096 | 273 | tx_isolation | REPEATABLE-READ | 274 | unique_checks | ON | 275 | updatable_views_with_limit | YES | 276 | version | 5.1.73 | 277 | version_comment | Source distribution | 278 | version_compile_machine | x86_64 | 279 | version_compile_os | redhat-linux-gnu | 280 | wait_timeout | 28800 | 281 | warning_count | 0 | 282 +-----------------------------------------+-------------------------------------------------------------------------------------------+ 283 [root@yinzhengjie ~]#
六.GUI客戶端工具
1>.Navicat for mysql
2>.SQLyog
3>.MySQL Front
4>.phpMyAdmin
5>.MySQL Query Browser
6>.MySQL Administrator
7>.MySQL Workbench
