{"id":11568,"date":"2019-03-14T12:56:39","date_gmt":"2019-03-14T12:56:39","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11568"},"modified":"2019-03-14T12:56:39","modified_gmt":"2019-03-14T12:56:39","slug":"20-mysql-mysqladmin-commands-for-database-administration-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/20-mysql-mysqladmin-commands-for-database-administration-in-linux\/","title":{"rendered":"20 MySQL (Mysqladmin) Commands for Database Administration in Linux"},"content":{"rendered":"<p><strong>mysqladmin<\/strong>\u00a0is a command-line utility the comes with\u00a0<strong>MySQL<\/strong>\u00a0server and it is used by\u00a0<strong>Database Administrators<\/strong>to perform some basic\u00a0<strong>MySQL<\/strong>\u00a0tasks easily such as setting root password, changing root password, monitoring mysql processes, reloading privileges, checking server status etc.<\/p>\n<p>In this article we\u2019ve compiled some very useful \u2018<strong>mysqladmin<\/strong>\u2018 commands that are used by system\/database administrators in their day-to-day work. You must have\u00a0<strong>MySQL<\/strong>\u00a0server installed on your system to perform these tasks.<\/p>\n<div id=\"attachment_1481\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/mysqladmin-commands.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1481\" title=\"mysqladmin commands\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/mysqladmin-commands-300x221.jpg\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/mysqladmin-commands-300x221.jpg 300w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/mysqladmin-commands.jpg 435w\" alt=\"mysqladmin commands\" width=\"300\" height=\"221\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">20 mysqladmin commands examples<\/p>\n<\/div>\n<p>If you don\u2019t have\u00a0<strong>MySQL<\/strong>\u00a0server installed or you are using older version of\u00a0<strong>MySQL<\/strong>\u00a0server, then we recommend you all to install or update your version by following our below article.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-mysql-on-rhel-centos-6-5-fedora-17-12\/\" target=\"_blank\" rel=\"noopener\">Installation of MySQL 5.5.28 Server on RHEL\/CentOS\/Fedora<\/a><\/li>\n<\/ol>\n<h3>1. How to set MySQL Root password?<\/h3>\n<p>If you have fresh installation of\u00a0<strong>MySQL<\/strong>\u00a0server, then it doesn\u2019t required any password to connect it as root user. To set\u00a0<strong>MySQL<\/strong>\u00a0password for root user, use the following command.<\/p>\n<pre># mysqladmin -u root password <strong>YOURNEWPASSWORD<\/strong><\/pre>\n<h3>2. How to Change MySQL Root password?<\/h3>\n<p>If you would like to change or update\u00a0<strong>MySQL<\/strong>\u00a0root password, then you need to type the following command. For example, say your old password is\u00a0<strong>123456<\/strong>\u00a0and you want to change it with new password say\u00a0<strong>xyz123<\/strong>.<\/p>\n<pre>mysqladmin -u root -p<strong>123456<\/strong> password '<strong>xyz123<\/strong>'<\/pre>\n<h3>3. How to check MySQL Server is running?<\/h3>\n<p>To find out whether\u00a0<strong>MySQL<\/strong>\u00a0server is up and running, use the following command.<\/p>\n<pre># mysqladmin -u root -p ping\r\n\r\nEnter password:\r\n<strong>mysqld is alive<\/strong><\/pre>\n<h3>4. How to Check which MySQL version I am running?<\/h3>\n<p>The following command shows\u00a0<strong>MySQL<\/strong>\u00a0version along with the current running status .<\/p>\n<pre># mysqladmin -u root -p version\r\n\r\nEnter password:\r\nmysqladmin  Ver 8.42 Distrib <strong>5.5.28<\/strong>, for Linux on i686\r\nCopyright (c) 2000, 2012, Oracle and\/or its affiliates. All rights reserved.\r\n\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nServer version          5.5.28\r\nProtocol version        10\r\nConnection              Localhost via UNIX socket\r\nUNIX socket             \/var\/lib\/mysql\/mysql.sock\r\nUptime:                 7 days 14 min 45 sec\r\n\r\nThreads: 2  Questions: 36002  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.059<\/pre>\n<h3>5. How to Find out current Status of MySQL server?<\/h3>\n<p>To find out current status of\u00a0<strong>MySQL<\/strong>\u00a0server, use the following command. The\u00a0<strong>mysqladmin<\/strong>\u00a0command shows the status of\u00a0<strong>uptime<\/strong>\u00a0with running\u00a0<strong>threads<\/strong>\u00a0and\u00a0<strong>queries<\/strong>.<\/p>\n<pre># mysqladmin -u root -ptmppassword status\r\n\r\nEnter password:\r\nUptime: 606704  Threads: 2  Questions: 36003  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.059<\/pre>\n<h3>6. How to check status of all MySQL Server Variable\u2019s and value\u2019s?<\/h3>\n<p>To check all the running status of\u00a0<strong>MySQL<\/strong>\u00a0server variables and values, type the following command. The output would be similar to below.<\/p>\n<pre># mysqladmin -u root -p extended-status\r\n\r\nEnter password:\r\n+------------------------------------------+-------------+\r\n| Variable_name                            | Value       |\r\n+------------------------------------------+-------------+\r\n| Aborted_clients                          | 3           |\r\n| Aborted_connects                         | 3           |\r\n| Binlog_cache_disk_use                    | 0           |\r\n| Binlog_cache_use                         | 0           |\r\n| Binlog_stmt_cache_disk_use               | 0           |\r\n| Binlog_stmt_cache_use                    | 0           |\r\n| Bytes_received                           | 6400357     |\r\n| Bytes_sent                               | 2610105     |\r\n| Com_admin_commands                       | 3           |\r\n| Com_assign_to_keycache                   | 0           |\r\n| Com_alter_db                             | 0           |\r\n| Com_alter_db_upgrade                     | 0           |\r\n| Com_alter_event                          | 0           |\r\n| Com_alter_function                       | 0           |\r\n| Com_alter_procedure                      | 0           |\r\n| Com_alter_server                         | 0           |\r\n| Com_alter_table                          | 0           |\r\n| Com_alter_tablespace                     | 0           |\r\n+------------------------------------------+-------------+<\/pre>\n<h3>7. How to see all MySQL server Variables and Values?<\/h3>\n<p>To see all the running variables and values of\u00a0<strong>MySQL<\/strong>\u00a0server, use the command as follows.<\/p>\n<pre># mysqladmin  -u root -p variables\r\n\r\nEnter password:\r\n+---------------------------------------------------+----------------------------------------------+\r\n| Variable_name                                     | Value                                        |\r\n+---------------------------------------------------+----------------------------------------------+\r\n| auto_increment_increment                          | 1                                            |\r\n| auto_increment_offset                             | 1                                            |\r\n| autocommit                                        | ON                                           |\r\n| automatic_sp_privileges                           | ON                                           |\r\n| back_log                                          | 50                                           |\r\n| basedir                                           | \/usr                                         |\r\n| big_tables                                        | OFF                                          |\r\n| binlog_cache_size                                 | 32768                                        |\r\n| binlog_direct_non_transactional_updates           | OFF                                          |\r\n| binlog_format                                     | STATEMENT                                    |\r\n| binlog_stmt_cache_size                            | 32768                                        |\r\n| bulk_insert_buffer_size                           | 8388608                                      |\r\n| character_set_client                              | latin1                                       |\r\n| character_set_connection                          | latin1                                       |\r\n| character_set_database                            | latin1                                       |\r\n| character_set_filesystem                          | binary                                       |\r\n| character_set_results                             | latin1                                       |\r\n| character_set_server                              | latin1                                       |\r\n| character_set_system                              | utf8                                         |\r\n| character_sets_dir                                | \/usr\/share\/mysql\/charsets\/                   |\r\n| collation_connection                              | latin1_swedish_ci                            |\r\n+---------------------------------------------------+----------------------------------------------+<\/pre>\n<h3>8. How to check all the running Process of MySQL server?<\/h3>\n<p>The following command will display all the running process of\u00a0<strong>MySQL<\/strong>\u00a0database queries.<\/p>\n<pre># mysqladmin -u root -p processlist\r\n\r\nEnter password:\r\n+-------+---------+-----------------+---------+---------+------+-------+------------------+\r\n| Id    | User    | Host            | db      | Command | Time | State | Info             |\r\n+-------+---------+-----------------+---------+---------+------+-------+------------------+\r\n| 18001 | rsyslog | localhost:38307 | rsyslog | Sleep   | 5590 |       |                  |\r\n| 18020 | root    | localhost       |         | Query   | 0    |       | show processlist |\r\n+-------+---------+-----------------+---------+---------+------+-------+------------------+<\/pre>\n<h3>9. How to create a Database in MySQL server?<\/h3>\n<p>To create a new database in\u00a0<strong>MySQL<\/strong>\u00a0server, use the command as shown below.<\/p>\n<pre># mysqladmin -u root -p create databasename\r\n\r\nEnter password:<\/pre>\n<pre># mysql -u root -p\r\n\r\nEnter password:\r\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\r\nYour MySQL connection id is 18027\r\nServer version: 5.5.28 MySQL Community Server (GPL) by Remi\r\n\r\nCopyright (c) 2000, 2012, Oracle and\/or its affiliates. All rights reserved.\r\n\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nmysql&gt; show databases;\r\n+--------------------+\r\n| Database           |\r\n+--------------------+\r\n| information_schema |\r\n| <strong>databasename<\/strong>       |\r\n| mysql              |\r\n| test               |\r\n+--------------------+\r\n8 rows in set (0.01 sec)\r\n\r\nmysql&gt;<\/pre>\n<h3>10. How to drop a Database in MySQL server?<\/h3>\n<p>To drop a Database in\u00a0<strong>MySQL<\/strong>\u00a0server, use the following command. You will be asked to confirm press \u2018<strong>y<\/strong>\u2018.<\/p>\n<pre># mysqladmin -u root -p drop databasename\r\n\r\nEnter password:\r\nDropping the database is potentially a very bad thing to do.\r\nAny data stored in the database will be destroyed.\r\n\r\nDo you really want to drop the 'databasename' database [y\/N] y\r\nDatabase \"databasename\" dropped<\/pre>\n<h3>11. How to reload\/refresh MySQL Privileges?<\/h3>\n<p>The\u00a0<strong>reload<\/strong>\u00a0command tells the server to reload the grant tables. The\u00a0<strong>refresh<\/strong>\u00a0command flushes all tables and reopens the log files.<\/p>\n<pre># mysqladmin -u root -p reload;\r\n# mysqladmin -u root -p refresh<\/pre>\n<h3>12. How to shutdown MySQL server Safely?<\/h3>\n<p>To shutdown\u00a0<strong>MySQL<\/strong>\u00a0server safely, type the following command.<\/p>\n<pre>mysqladmin -u root -p shutdown\r\n\r\nEnter password:<\/pre>\n<p>You can also use the following commands to start\/stop MySQL server.<\/p>\n<pre># \/etc\/init.d\/mysqld stop\r\n# \/etc\/init.d\/mysqld start<\/pre>\n<h3>13. Some useful MySQL Flush commands<\/h3>\n<p>Following are some useful flush commands with their description.<\/p>\n<ol>\n<li><strong>flush-hosts<\/strong>: Flush all host information from host cache.<\/li>\n<li><strong>flush-tables<\/strong>: Flush all tables.<\/li>\n<li><strong>flush-threads<\/strong>: Flush all threads cache.<\/li>\n<li><strong>flush-logs<\/strong>: Flush all information logs.<\/li>\n<li><strong>flush-privileges<\/strong>: Reload the grant tables (same as reload).<\/li>\n<li><strong>flush-status<\/strong>: Clear status variables.<\/li>\n<\/ol>\n<pre># mysqladmin -u root -p flush-hosts\r\n# mysqladmin -u root -p flush-tables\r\n# mysqladmin -u root -p flush-threads\r\n# mysqladmin -u root -p flush-logs\r\n# mysqladmin -u root -p flush-privileges\r\n# mysqladmin -u root -p flush-status<\/pre>\n<h3>14. How to kill Sleeping MySQL Client Process?<\/h3>\n<p>Use the following command to identify sleeping\u00a0<strong>MySQL<\/strong>\u00a0client process.<\/p>\n<pre># mysqladmin -u root -p processlist\r\n\r\nEnter password:\r\n+----+------+-----------+----+---------+------+-------+------------------+\r\n| Id | User | Host      | db | Command | Time | State | Info             |\r\n+----+------+-----------+----+---------+------+-------+------------------+\r\n| 5  | root | localhost |    | Sleep   | 14   |       |\t\t\t\t\t |\r\n| 8  | root | localhost |    | Query   | 0    |       | show processlist |\r\n+----+------+-----------+----+---------+------+-------+------------------+<\/pre>\n<p>Now, run the following command with\u00a0<strong>kill<\/strong>\u00a0and\u00a0<strong>process ID<\/strong>\u00a0as shown below.<\/p>\n<pre># mysqladmin -u root -p kill 5\r\n\r\nEnter password:\r\n+----+------+-----------+----+---------+------+-------+------------------+\r\n| Id | User | Host      | db | Command | Time | State | Info             |\r\n+----+------+-----------+----+---------+------+-------+------------------+\r\n| 12 | root | localhost |    | Query   | 0    |       | show processlist |\r\n+----+------+-----------+----+---------+------+-------+------------------+<\/pre>\n<p>If you like to\u00a0<strong>kill<\/strong>\u00a0multiple process, then pass the\u00a0<strong>process ID<\/strong>\u2018s with comma separated as shown below.<\/p>\n<pre># mysqladmin -u root -p kill 5,10<\/pre>\n<h3>15. How to run multiple mysqladmin commands together?<\/h3>\n<p>If you would like to execute multiple \u2018<strong>mysqladmin<\/strong>\u2018 commands together, then the command would be like this.<\/p>\n<pre># mysqladmin  -u root -p processlist status version\r\n\r\nEnter password:\r\n+----+------+-----------+----+---------+------+-------+------------------+\r\n| Id | User | Host      | db | Command | Time | State | Info             |\r\n+----+------+-----------+----+---------+------+-------+------------------+\r\n| 8  | root | localhost |    | Query   | 0    |       | show processlist |\r\n+----+------+-----------+----+---------+------+-------+------------------+\r\nUptime: 3801  Threads: 1  Questions: 15  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.003\r\nmysqladmin  Ver 8.42 Distrib 5.5.28, for Linux on i686\r\nCopyright (c) 2000, 2012, Oracle and\/or its affiliates. All rights reserved.\r\n\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nServer version          5.5.28\r\nProtocol version        10\r\nConnection              Localhost via UNIX socket\r\nUNIX socket             \/var\/lib\/mysql\/mysql.sock\r\nUptime:                 1 hour 3 min 21 sec\r\n\r\nThreads: 1  Questions: 15  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.003<\/pre>\n<h3>16. How to Connect remote mysql server<\/h3>\n<p>To connect remote\u00a0<strong>MySQL<\/strong>\u00a0server, use the\u00a0<strong>-h<\/strong>\u00a0(<strong>host<\/strong>)\u00a0 with\u00a0<strong>IP Address<\/strong>\u00a0of remote machine.<\/p>\n<pre># mysqladmin  -h 172.16.25.126 -u root -p<\/pre>\n<h3>17. How to execute command on remote MySQL server<\/h3>\n<p>Let\u2019s say you would like to see the\u00a0<strong>status<\/strong>\u00a0of remote\u00a0<strong>MySQL<\/strong>\u00a0server, then the command would be.<\/p>\n<pre># mysqladmin  -h 172.16.25.126 -u root -p status<\/pre>\n<h3>18. How to start\/stop MySQL replication on a slave server?<\/h3>\n<p>To start\/stop\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-setup-mysql-master-slave-replication-in-rhel-centos-fedora\/\" target=\"_blank\" rel=\"noopener\">MySQL replication<\/a>\u00a0on salve server, use the following commands.<\/p>\n<pre># mysqladmin  -u root -p start-slave<\/pre>\n<pre># mysqladmin  -u root -p stop-slave<\/pre>\n<h3>19. How to store MySQL server Debug Information to logs?<\/h3>\n<p>It tells the server to write debug information about locks in use, used memory and query usage to the\u00a0<strong>MySQL<\/strong>\u00a0log file including information about event scheduler.<\/p>\n<pre># mysqladmin  -u root -p debug\r\n\r\nEnter password:<\/pre>\n<h3>20. How to view mysqladmin options and usage<\/h3>\n<p>To find out more options and usage of\u00a0<strong>myslqadmin<\/strong>\u00a0command use the help command as shown below. It will display a list of available options.<\/p>\n<pre># mysqladmin --help<\/pre>\n<p>We have tried our best to include almost all of \u2018<strong>mysqladmin<\/strong>\u2018 commands with their examples in this article, If still, we\u2019ve missed anything, please do let us know via comments and don\u2019t forget to share with your friends.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/mysqladmin-commands-for-database-administration-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysqladmin\u00a0is a command-line utility the comes with\u00a0MySQL\u00a0server and it is used by\u00a0Database Administratorsto perform some basic\u00a0MySQL\u00a0tasks easily such as setting root password, changing root password, monitoring mysql processes, reloading privileges, checking server status etc. In this article we\u2019ve compiled some very useful \u2018mysqladmin\u2018 commands that are used by system\/database administrators in their day-to-day work. You &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/20-mysql-mysqladmin-commands-for-database-administration-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;20 MySQL (Mysqladmin) Commands for Database Administration in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11568","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11568"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11568\/revisions"}],"predecessor-version":[{"id":11569,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11568\/revisions\/11569"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}