Introduction to using the MySQL mysqladmin client

Introduction to using the MySQL mysqladmin client

mysqladmin is a shell command line tool officially provided by MySQL. Its parameters need to be executed in the shell command line. When we use mysqladmin, we must specify two types of parameters, one is connection parameters, and the other is command parameters. Connection parameters are used to specify the corresponding connection information, while command parameters are used to specify command information, such as checking the configuration and current status of the server, creating and deleting databases, etc. Its syntax is as follows:

mysqladmin [options] command [command-options] [command [command options]] ...

In addition, there are some related parameter configurations (you can slide the code to the left~):

--bind-address=name Bind the IP address of the remote access host -i, --sleep=# How long does it take to execute it?
-c, --count=# Statistics count. Use with the i option.
-f, --force Force execution. No confirmation is required when deleting a database. When multiple statements are executed, errors in one of the statements will be ignored.
--default-character-set=name Set the default character set.
-?, --help Display help information.
-h, --host=name specifies the connection host.
-u, --user=name Login user.
-p, --password[=name] Login password. If it is not written after the parameter, you will be prompted to enter it.
-P, --port=# Specify the database port.
--protocol=name The connection protocol to use. (tcp, socket, pipe, memory)
-r, --relative Show the difference between the previous and the next output. Must be used with the i option.
-s, --silent Exit silently.
-S, --socket=name specifies the socket file.
-v, --verbose Display more information.
-V, --version Display version information.
-w, --wait[=#] If the connection is disconnected, wait for the specified time and try again

There are so many parameters, it may seem a bit confusing, so let's take a look at what it can do for us:

1. Check the status of the server:

#Check the server status every two seconds [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

2. Change the root password:

#Change the root password mysqladmin -u root -p original password password 'newpassword'

3. Check whether mysqlserver is available

#Query whether the service is normal [root@dev01 ~]# mysqladmin -uroot -p ping
Enter password: 
mysqld is alive

4. Query the server version

[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 seconds

Threads: 2 Questions: 538 Slow queries: 0 Opens: 346 Flush tables: 1 Open tables: 285 Queries per second avg: 0.012

5. View the current status value of the system (omit some results)

[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 | |
+-----------------------------------------------+----------+

6. View the server system variable value

[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/ |
......

7. View all current processes

[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 |
+----+------+----------------------+----------+----------+----------+----------+------------------+

8. Create a database

[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

From the above command we can see that we have created the database db_test through the create command

9. Delete a specific database:

[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)

In our daily operations, the drop operation should be cautious. As you can see, MySQL also gives a friendly reminder.

10. Reload the permission table and refresh the cache (no obvious output)

[root@dev01 ~]# mysqladmin -uroot -p reload
Enter password:
[root@dev01 ~]# mysqladmin -uroot -p refresh
Enter password:

11. Enable safe mode and close the database

[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

12. Various refresh commands

[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

13. Stop and start the MySQL slave replication process

[root@dev01 ~]# mysqladmin -u root -p stop-slave
[root@dev01 ~]# mysqladmin -u root -p start-slave

The above are some of the most commonly used functions of mysqladmin. Those marked in red are generally used in a wide range of work, so you can pay more attention to them.

The above is the detailed content of the introduction to the use of MySQL mysqladmin client. For more information about MySQL mysqladmin client, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How does MySQL connect to the corresponding client process?
  • Solve the problem of MySql client exiting in seconds (my.ini not found)
  • PHP Swoole asynchronous MySQL client implementation example
  • Solve the problem that the Node.js mysql client does not support the authentication protocol
  • Solution to the problem that the mysql8.0.11 client cannot log in
  • Detailed explanation of MySQL/Java server support for emoji and problem solving
  • Getting started with NodeJS server development (Express+MySQL)
  • MySQL connection pool for App server (supports high concurrency)
  • Interpreting MySQL client and server protocols

<<:  3 codes for automatic refresh of web pages

>>:  Solve the problem of docker's tls (ssl) certificate expiration

Recommend

React example of how to get the value of the input box

React multiple ways to get the value of the input...

Specific use of CSS front-end page rendering optimization attribute will-change

Preface When scroll events such as scroll and res...

Implementation of crawler Scrapy image created by dockerfile based on alpine

1. Download the alpine image [root@DockerBrian ~]...

Detailed tutorial on replacing mysql8.0.17 in windows10

This article shares the specific steps of replaci...

Briefly explain the use of group by in sql statements

1. Overview Group by means to group data accordin...

Analysis of the Docker deployment Consul configuration process

Execute Command docker run -d --name consul -p 85...

Detailed explanation of CSS style cascading rules

CSS style rule syntax style is the basic unit of ...

Detailed explanation of mandatory and implicit conversion of types in JavaScript

Table of contents 1. Implicit conversion Conversi...

About VSCode formatting JS automatically adding or removing semicolons

introduction It is okay to add or not add a semic...

Solution for converting to inline styles in CSS (css-inline)

Talk about the scene Send Email Embedding HTML in...

Experience in designing a layered interface in web design

Many netizens often ask why their websites always ...

【HTML element】How to embed images

The img element allows us to embed images in HTML...

Detailed explanation of MySql data type tutorial examples

Table of contents 1. Brief Overview 2. Detailed e...