mysqladmin是一個MySQL服務器命令行工具,它由Database Administrators執行一些基本的命令諸如更改 root 密碼、監控 mysql 進程、重新加載權限、檢查服務器狀態等任務。
如果你想更改MySQL
root密碼,然后你需要鍵入以下命令。
123456rumenz123>?mysqladmin?-u?root?-p?123456?password?rumenz123
查看
MySQL服務器運行狀態
>?mysqladmin?-u?root?-p?ping
Enter?password:
mysqld?is?alive
顯示
MySQL版本以及當前運行狀態。
>?mysqladmin?-u?root?-p?version
Enter?password:
mysqladmin??Ver?8.0.27?for?macos10.14?on?x86_64?(Homebrew)
Copyright?(c)?2000,?2021,?Oracle?and/or?its?affiliates.
Oracle?is?a?registered?trademark?of?Oracle?Corporation?and/or?its
affiliates.?Other?names?may?be?trademarks?of?their?respective
owners.
Server?version??8.0.27
Protocol?version?10
Connection??Localhost?via?UNIX?socket
UNIX?socket??/tmp/mysql.sock
Uptime:???5?days?5?hours?46?min?40?sec
Threads:?2??Questions:?140408??Slow?queries:?0??Opens:?727??Flush?tables:?3??Open?tables:?624??Queries?per?second?avg:?0.310
查看當前
MySQL服務器狀態。mysqladmin命令顯示狀態uptime,threads和queries.
>?mysqladmin?-u?root?-p??status
Uptime:?452778??Threads:?2??Questions:?140406??Slow?queries:?0??Opens:?727??Flush?tables:?3??Open?tables:?624??Queries?per?second?avg:?0.310
檢查
MySQL服務器變量和值
>?mysqladmin?-u?root?-p?extended-status
Enter?password:
+------------------------------------------+-------------+
|?Variable_name????????????????????????????|?Value???????|
+------------------------------------------+-------------+
|?Aborted_clients??????????????????????????|?3???????????|
|?Aborted_connects?????????????????????????|?3???????????|
|?Binlog_cache_disk_use????????????????????|?0???????????|
|?Binlog_cache_use?????????????????????????|?0???????????|
|?Binlog_stmt_cache_disk_use???????????????|?0???????????|
|?Binlog_stmt_cache_use????????????????????|?0???????????|
|?Bytes_received???????????????????????????|?6400357?????|
|?Bytes_sent???????????????????????????????|?2610105?????|
|?Com_admin_commands???????????????????????|?3???????????|
|?Com_assign_to_keycache???????????????????|?0???????????|
|?Com_alter_db?????????????????????????????|?0???????????|
|?Com_alter_db_upgrade?????????????????????|?0???????????|
|?Com_alter_event??????????????????????????|?0???????????|
|?Com_alter_function???????????????????????|?0???????????|
|?Com_alter_procedure??????????????????????|?0???????????|
|?Com_alter_server?????????????????????????|?0???????????|
|?Com_alter_table??????????????????????????|?0???????????|
|?Com_alter_tablespace?????????????????????|?0???????????|
+------------------------------------------+-------------+
查看
MySQL變量和值
>?mysqladmin??-u?root?-p?variables
Enter?password:
+---------------------------------------------------+----------------------------------------------+
|?Variable_name?????????????????????????????????????|?Value????????????????????????????????????????|
+---------------------------------------------------+----------------------------------------------+
|?auto_increment_increment??????????????????????????|?1????????????????????????????????????????????|
|?auto_increment_offset?????????????????????????????|?1????????????????????????????????????????????|
|?autocommit????????????????????????????????????????|?ON???????????????????????????????????????????|
|?automatic_sp_privileges???????????????????????????|?ON???????????????????????????????????????????|
|?back_log??????????????????????????????????????????|?50???????????????????????????????????????????|
|?basedir???????????????????????????????????????????|?/usr?????????????????????????????????????????|
|?big_tables????????????????????????????????????????|?OFF??????????????????????????????????????????|
|?binlog_cache_size?????????????????????????????????|?32768????????????????????????????????????????|
|?binlog_direct_non_transactional_updates???????????|?OFF??????????????????????????????????????????|
|?binlog_format?????????????????????????????????????|?STATEMENT????????????????????????????????????|
|?binlog_stmt_cache_size????????????????????????????|?32768????????????????????????????????????????|
|?bulk_insert_buffer_size???????????????????????????|?8388608??????????????????????????????????????|
|?character_set_client??????????????????????????????|?latin1???????????????????????????????????????|
|?character_set_connection??????????????????????????|?latin1???????????????????????????????????????|
|?character_set_database????????????????????????????|?latin1???????????????????????????????????????|
|?character_set_filesystem??????????????????????????|?binary???????????????????????????????????????|
|?character_set_results?????????????????????????????|?latin1???????????????????????????????????????|
|?character_set_server??????????????????????????????|?latin1???????????????????????????????????????|
|?character_set_system??????????????????????????????|?utf8?????????????????????????????????????????|
|?character_sets_dir????????????????????????????????|?/usr/share/mysql/charsets/???????????????????|
|?collation_connection??????????????????????????????|?latin1_swedish_ci????????????????????????????|
+---------------------------------------------------+----------------------------------------------+
>?mysqladmin?-u?root?-p?processlist
Enter?password:
+-------+---------+-----------------+---------+---------+------+-------+------------------+
|?Id????|?User????|?Host????????????|?db??????|?Command?|?Time?|?State?|?Info?????????????|
+-------+---------+-----------------+---------+---------+------+-------+------------------+
|?18001?|?rsyslog?|?localhost:38307?|?rsyslog?|?Sleep???|?5590?|???????|??????????????????|
|?18020?|?root????|?localhost???????|?????????|?Query???|?0????|???????|?show?processlist?|
+-------+---------+-----------------+---------+---------+------+-------+------------------+
創建數據庫。
>?mysqladmin?-u?root?-p?create?rumenz_test
Enter?password:
通過
mysqladmin創建數據庫
>?mysqladmin?-u?root?-p?drop?rumenz_test
Dropping?the?database?is?potentially?a?very?bad?thing?to?do.
Any?data?stored?in?the?database?will?be?destroyed.
Do?you?really?want?to?drop?the?'rumenz_test'?database?[y/N]?y
Database?"rumenz_test"?dropped
reload命令告訴服務器重新加載授權表。refresh命令刷新所有表并重新打開日志文件。
>?mysqladmin?-u?root?-p?reload
>?mysqladmin?-u?root?-p?refresh
>?mysqladmin?-u?root?-p?shutdown
Enter?password:
flush-hosts:從主機緩存中刷新所有主機信息。flush-tables: 刷新所有表。flush-threads:刷新所有線程緩存。flush-logs:刷新所有信息日志。flush-privileges:重新加載授權表(與重新加載相同)。flush-status:清除狀態變量。#?mysqladmin?-u?root?-p?flush-hosts
#?mysqladmin?-u?root?-p?flush-tables
#?mysqladmin?-u?root?-p?flush-threads
#?mysqladmin?-u?root?-p?flush-logs
#?mysqladmin?-u?root?-p?flush-privileges
#?mysqladmin?-u?root?-p?flush-status
找出休眠的進程
>?mysqladmin?-u?root?-p?processlist
Enter?password:
+----+------+-----------+----+---------+------+-------+------------------+
|?Id?|?User?|?Host??????|?db?|?Command?|?Time?|?State?|?Info?????????????|
+----+------+-----------+----+---------+------+-------+------------------+
|?5??|?root?|?localhost?|????|?Sleep???|?14???|???????|??????|
|?8??|?root?|?localhost?|????|?Query???|?0????|???????|?show?processlist?|
+----+------+-----------+----+---------+------+-------+------------------+
用
kill和process ID殺死
>?mysqladmin?-u?root?-p?kill?5
Enter?password:
+----+------+-----------+----+---------+------+-------+------------------+
|?Id?|?User?|?Host??????|?db?|?Command?|?Time?|?State?|?Info?????????????|
+----+------+-----------+----+---------+------+-------+------------------+
|?12?|?root?|?localhost?|????|?Query???|?0????|???????|?show?processlist?|
+----+------+-----------+----+---------+------+-------+------------------+
如果需要
kill多個進程,用逗號分隔多個process ID
>?mysqladmin?-u?root?-p?kill?5,10
同時執行多個
mysqladmin命令
>?mysqladmin??-u?root?-p?processlist?status?version
Enter?password:
+----+------+-----------+----+---------+------+-------+------------------+
|?Id?|?User?|?Host??????|?db?|?Command?|?Time?|?State?|?Info?????????????|
+----+------+-----------+----+---------+------+-------+------------------+
|?8??|?root?|?localhost?|????|?Query???|?0????|???????|?show?processlist?|
+----+------+-----------+----+---------+------+-------+------------------+
Uptime:?3801??Threads:?1??Questions:?15??Slow?queries:?0??Opens:?15??Flush?tables:?1??Open?tables:?8??Queries?per?second?avg:?003
mysqladmin??Ver?42?Distrib?28,?for?Linux?on?i686
Copyright?(c)?2000,?2012,?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.
Server?version??????????28
Protocol?version????????10
Connection??????????????Localhost?via?UNIX?socket
UNIX?socket?????????????/var/lib/mysql/mysql.sock
Uptime:?????????????????1?hour?3?min?21?sec
Threads:?1??Questions:?15??Slow?queries:?0??Opens:?15??Flush?tables:?1??Open?tables:?8??Queries?per?second?avg:?003
連接遠程
MySQL服務器,使用-h(host) 和IP Address參數
>?mysqladmin??-h?rumenz.com?-u?root?-p
如果想查看遠程的
MySQL服務器的status
>?mysqladmin??-h?rumenz.com?-u?root?-p?status
要在從服務器上啟動/停止MySQL 復制,使用以下命令。
>?mysqladmin??-u?root?-p?start-slave
>?mysqladmin??-u?root?-p?stop-slave
將有關正在使用的鎖、已用內存和查詢使用情況的調試信息寫入
MySQL日志文件(包括有關事件調度程序的信息)。
>?mysqladmin??-u?root?-p?debug
Enter?password:
了解更多
myslqadmin命令選項和用法。
>?mysqladmin?--help

END
→點關注,不迷路←