Method 1: Use command line tools
1. Use the mysql command
Log in to MySQL on the command line and view the version information:
mysql -u [username] -p
After logging in, execute the following SQL command to view the version:
SHOW VARIABLES LIKE 'version';
Or directly queryversion()
Function:
SELECT version();
Example:
mysql -u root -p Enter password:
After logging in:
mysql> SHOW VARIABLES LIKE 'version'; +---------------+-----------+ | Variable_name | Value | +---------------+-----------+ | version | 8.0.23 | +---------------+-----------+ 1 row in set (0.01 sec) mysql> SELECT version(); +-----------+ | version() | +-----------+ | 8.0.23 | +-----------+ 1 row in set (0.00 sec)
Method 2: Use the mysqladmin command
mysqladmin
It is a MySQL management tool that allows you to view version information directly from the command line.
mysqladmin -u [username] -p version
Example:
mysqladmin -u root -p version Enter password:
Output example:
mysqladmin Ver 8.0.23 for Linux on x86_64 (MySQL Community Server - GPL) Copyright (c) 2000, 2021, 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 8.0.23 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/ Uptime: 1 hour 12 min 34 sec Threads: 2 Questions: 3245 Slow queries: 0 Opens: 43 Flush tables: 2 Open tables: 36 Queries per second avg: 0.745
Method 3: Use graphical management tools
1. Using MySQL Workbench
- Open MySQL Workbench.
- Connect to your MySQL server.
- In the navigation pane on the left, select Database Connection.
- In the Navigator pane, select Server Status and you will be able to see the server version information.
2. Use phpMyAdmin
- Open phpMyAdmin.
- Log in to your MySQL database.
- On the home page, you can see the server version information in the upper right corner.
Method 4: Use program code
1. Using Python
Can be used through Pythonmysql-connector
Module to get the MySQL version.
import conn = ( host="localhost", user="root", password="your_password" ) cursor = () ("SELECT version()") version = () print("MySQL version:", version[0]) () ()
2. Use PHP
Can be passed through PHPmysqli
Extend to get the MySQL version.
<?php $servername = "localhost"; $username = "root"; $password = "your_password"; // Create a connection$conn = new mysqli($servername, $username, $password); // Check the connectionif ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Query MySQL version$result = $conn->query("SELECT version()"); $row = $result->fetch_assoc(); echo "MySQL version: " . $row["version()"]; $conn->close(); ?>
Summarize
Viewing the information about the MySQL database version can be achieved through various methods such as command line tools, SQL query statements, graphical management tools and program code. Select the appropriate method to obtain version information according to specific needs and environment.
This is the end of this article about the four methods of viewing MySQL database version. For more information about viewing MySQL version, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!