Introduction
MySql is a relational database management system (RDBMS) most widely used in several web applications and enterprise environments. For the effective management of compatibility, troubleshooting, planning for upgrades, etc., it is important to know which version of MySQL is running on your system.
There are a few fairly simple ways to check the version of MySQL that’s installed on a Linux based system—all achieved with command line tools. The following commands, taken from this guide, allow you to quickly find what version of MySQL you are running without a graphical user interface.
Check MySQL Version with the V Command
To check the MySQL version using the -V (uppercase V) option, you can use the following command:
mysql -V
Explanation:
- mysql: This is the MySQL client command-line tool.
- -V: This option tells the mysql command to display the version of the MySQL client and server.
- Example output:
mysql Ver 8.0.23 for Linux on x86_64 (MySQL Community Server - GPL)
This command will display the MySQL version information, including the version number (e.g., 8.0.23), the platform (e.g., Linux), and the architecture (e.g., x86_64).
Using mysql -V is a quick and easy way to check the MySQL version on your system.
Find a MySQL Version Number with a MySQL Command
To find the MySQL version number using a MySQL command, follow these steps:
1.Log in to the MySQL shell:
mysql -u root -p
Replace root with your MySQL username if necessary. After running the command, you’ll be prompted to enter your MySQL password.
Run the SELECT VERSION() command:
Once you’re logged into the MySQL shell, use the following SQL command to retrieve the version number:
SELECT VERSION();
Press Enter after typing the command
Check the output:
The result will be something like:
+-------------------------+
| VERSION() |
+-------------------------+
| 8.0.23 |
+-------------------------+
1row in set (0.00 sec)
This shows the version number of MySQL that is currently running on your system (e.g., 8.0.23).
Summary:
By running the SELECT VERSION(); command within the MySQL shell, you can easily retrieve the MySQL version number.
The SHOW VARIABLES LIKE statement in MySQL is used to retrieve specific configuration settings or system variables. These variables provide information about the MySQL server’s current configuration, including version information, memory settings, and other server parameters.
To find the MySQL version number using SHOW VARIABLES LIKE, follow these steps:
1. Log in to the MySQL Shell
First, open a terminal and log into the MySQL shell:
mysql -u root -p
Replace root with your MySQL username if needed. After entering the command, you’ll be prompted to enter your MySQL password.
2. Run the SHOW VARIABLES LIKE Statement
To check the MySQL version, you can use the following command:
SHOW VARIABLES LIKE 'version';
This command will return the MySQL version along with the variable name.
3. Example Output
After running the command, you will see output similar to this:
+-------------------------+-----------+
| Variable_name | Value |
+-------------------------+-----------+
| version | 8.0.23 |
+-------------------------+-----------+
1 row in set (0.00 sec)
Here, the Value column shows the MySQL version (e.g., 8.0.23).
4. Using Wildcards
You can also use wildcards to search for other variables. For example, to search for all version-related variables, you can run:
SHOW VARIABLES LIKE '%version%';
This will return any variable whose name contains the word version, such as:
+-------------------------+----------------------+
| Variable_name | Value |
+-------------------------+----------------------+
| version | 8.0.23 |
| version_comment | MySQL Community Server |
Summary:
The SHOW VARIABLES LIKE ‘version’; statement is a useful way to retrieve MySQL version information directly from the MySQL server’s internal variables. This method can also be extended to search for other configuration variables by using patterns with the LIKE clause.
STATUS Command
The STATUS command in MySQL provides a summary of the current status of the MySQL server, including version information, connection details, and other important server statistics.
How to Use the STATUS Command:
1.Log in to the MySQL Shell:
First, open a terminal and log into MySQL with the following command:
mysql -u root -p
Replace root with your MySQL username if necessary. You will be prompted to enter the MySQL password.
Run the STATUS Command:
After you’re in the MySQL shell, type the following command:
STATUS;
Example Output:
After running the command, you will see output similar to the following:
| Server version: 8.0.23 |
| Protocol version: 10 |
| Connection: 127.0.0.1 via TCP/IP|
| Current database: (none) |
| Current user: root@localhost |
| SSL: Not in use |
| Uptime: 5 hours 3 min 20 sec |
| Threads: 1 (max: 10) |
| Questions: 100 (max: 10000) |
| Slow queries: 0 |
| Opens: 135 |
| Flush tables: 1 |
| Open tables: 50 |
| Queries per second avg: 0.556 |
Key Information in the STATUS Output:
- Server version: Shows the version of the MySQL server (e.g., 8.0.23).
- Protocol version: Indicates the MySQL protocol version in use.
- Connection: Shows the IP address and connection method used to connect to MySQL (e.g., 127.0.0.1 via TCP/IP).
- Current database: Displays the name of the database you are connected to (if any).
- Current user: Shows the current MySQL user and host.
- SSL: Indicates if SSL encryption is in use.
- Uptime: Displays how long the MySQL server has been running since its last start.
- Threads: Displays the number of active threads and the maximum allowed threads.
- Questions: Shows the number of queries the server has handled since it was started.
- Slow queries: Displays the number of slow queries.
- Opens: Indicates the number of tables that have been opened.
- Flush tables: The number of times tables have been flushed.
- Open tables: The number of tables that are currently open.
- Queries per second avg: Shows the average number of queries per second.
Summary:
The STATUS command is useful for obtaining a quick overview of the MySQL server’s current state, including version, server statistics, and connection details. This command can help you monitor server activity and troubleshoot issues.
Also Read :- https://onliveserver.com/how-to-add-users-in-linux/
Conclusion
Ensuring that your system is up-to-date on the latest version, will provide the best of experiences and data protection available. {These might be necessary for compatibility, security updates, and new feature usage.} You can get the version from the terminal pretty easily with the “mysql -v” command or from the MySQL command line tool with “SELECT VERSION()”. You can even find the MySQL version and other nitty-gritty through “SHOW VARIABLES LIKE” Finally, STATUS command will give you a short report about the version number and whether it is running or not. Knowing the MySQL version is important for security upgrades/patches, migration and documentation. Keeping current means that you’ll be running at peak efficiency and playing nicely with the rest of your software.