您好,登錄后才能下訂單哦!
小編給大家分享一下MySQL中mysqladmin客戶端的使用方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
mysqladmin是MySQL官方提供的shell命令行工具,它的參數都需要在shell命令行里面執行,當我們使用mysqladmin的時候,必須指定兩類參數,一類是連接參數,另外一類是命令參數,連接參數用來指定相應的連接信息,而命令參數用來指定命令信息,例如可以用來檢查服務器的配置和當前狀態、創建和刪除數據庫等。它的語法如下:
mysqladmin [options] command [command-options] [command [command options]] ...
除此之外,還有一些相關的參數配置(代碼可以左滑哦~):
--bind-address=name 綁定遠程訪問主機的ip地址 -i, --sleep=# 間隔多長時間執行一次。 -c, --count=# 統計計數。與i選項配合使用。 -f, --force 強制執行,刪除數據庫是無需確認信息,多條語句執行時忽略其中某條語句的錯誤。 --default-character-set=name 設置默認字符集。 -?, --help 顯示幫助信息。 -h, --host=name 指定連接主機。 -u, --user=name 登錄用戶。 -p, --password[=name] 登錄密碼,如果不寫于參數后,則會提示輸入。 -P, --port=# 指定數據庫端口。 --protocol=name 使用的連接協議。(tcp,socket,pipe,memory) -r, --relative 顯示前后兩次輸出的差異。必須與i選項配合使用。 -s, --silent 靜默退出。 -S, --socket=name 指定socket文件。 -v, --verbose 顯示更多信息。 -V, --version 顯示版本信息。 -w, --wait[=#] 如果連接斷開,等待指定的時間后重試
這么多參數,想看著比較亂,那么我們來看看它具體能夠幫我們做哪些事情吧:
#每隔兩秒查看一次服務器的狀態 [root@dev01 ~]# mysqladmin -uroot -p -i 2 -c 2 status Enter password: Uptime: 42767 Threads: 2 Questions: 533 Slow queries: 0 Opens: 346 Flush tables: Open tables: Queries per second avg: 0.012 Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.012
#修改root密碼 mysqladmin -u root -p原密碼 password 'newpassword'
#查詢服務是否正常 [root@dev01 ~]# mysqladmin -uroot -p ping Enter password: mysqld is alive
[root@dev01 ~]# mysqladmin -uroot -p version Enter password: mysqladmin Ver 8.42 Distrib 5.7.19, for linux-glibc2.12 on x86_64 Copyright (c) 2000, 2017, 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 5.7.19 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /tmp/mysql.sock Uptime: 12 hours 42 sec Threads: 2 Questions: 538 Slow queries: 0 Opens: 346 Flush tables: 1 Open tables: 285 Queries per second avg: 0.012
[root@dev01 ~]# mysqladmin -uroot -p extended-status Enter password: +-----------------------------------------------+----------+ | Variable_name | Value | +-----------------------------------------------+----------+ | Aborted_clients | | | Aborted_connects | | | Innodb_num_open_files | | | Innodb_truncated_status_writes | | | Uptime | | | Uptime_since_flush_status | | +-----------------------------------------------+----------+
[root@dev01 ~]# mysqladmin -uroot -p variables Enter password: ...... | key_cache_block_size | | | key_cache_division_limit | | | large_files_support | ON | | large_page_size | | | large_pages | OFF | | lc_messages | en_US | | lc_messages_dir | /usr/local/mysql/share/ | ......
[root@dev01 ~]# mysqladmin -uroot -p processlist Enter password: +----+------+----------------------+----------+---------+-------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+----------------------+----------+---------+-------+----------+------------------+ | | root | 192.168.56.102: | devopsdb | Sleep | | | | | | root | localhost | | Query | | starting | show processlist | +----+------+----------------------+----------+---------+-------+----------+------------------+
[root@dev01 ~]# mysqladmin -uroot -p create db_test Enter password: [root@dev01 ~]# mysql -uroot -p Enter password: mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | TkGrowDB_dbo | | TkGrowLog_dbo | | cydevopsdb | | db_test | | yeyz | +--------------------+ rows in set (0.00 sec) mysql> exit Bye
從上面的命令我們可以看到,我們已經通過create命令創建了數據庫db_test
[root@dev01 ~]# mysqladmin -uroot -p drop db_test Enter password: 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 'db_test' database [y/N] y Database "db_test" dropped [root@dev01 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | TkGrowDB_dbo | | TkGrowLog_dbo | | cydevopsdb | | yeyz | +--------------------+ rows in set (0.00 sec)
在我們日常操作中,drop操作應該謹慎一些,可以看到,mysql也友好的給出了提醒。
[root@dev01 ~]# mysqladmin -uroot -p reload Enter password: [root@dev01 ~]# mysqladmin -uroot -p refresh Enter password:
[root@dev01 ~]# ps -ef|grep mysqld root : ? :: /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/dev01.pid mysql : ? :: /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysqld.log --pid-file=/data/mysql/dev01.pid --socket=/tmp/mysql.sock root : pts/ :: grep mysqld [root@dev01 ~]# mysqladmin -uroot -p shutdown Enter password: [root@dev01 ~]# ps -ef|grep mysqld root : pts/ :: grep mysqld
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-hosts [root@dev01 ~]# mysqladmin -u root -ptmppassword flush-logs [root@dev01 ~]# mysqladmin -u root -ptmppassword flush-privileges [root@dev01 ~]# mysqladmin -u root -ptmppassword flush-status [root@dev01 ~]# mysqladmin -u root -ptmppassword flush-tables [root@dev01 ~]# mysqladmin -u root -ptmppassword flush-threads
[root@dev01 ~]# mysqladmin -u root -p stop-slave [root@dev01 ~]# mysqladmin -u root -p start-slave
以上是“MySQL中mysqladmin客戶端的使用方法”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。