To check the MySQL or MariaDB version in Linux: 1) Run `mysql -V` or `mysqld -V` from the terminal for instant CLI output, 2) Log into the database shell and execute `SELECT VERSION();` or `SHOW VARIABLES LIKE ‘%version%’;`, or 3) Use package managers such as `dpkg -l | grep -E ‘mysql-server|mariadb-server’` on Ubuntu/Debian or `rpm -qa | grep -E ‘mysql-server|mariadb-server’` on RHEL/AlmaLinux/CentOS.
Verifying the active database version is a fundamental task for Linux systems engineers, software developers, and webmasters. Whether preparing for a major CMS upgrade, auditing security patches, or verifying compatibility for web applications, knowing your exact database build is essential.
Different versions of MySQL (such as 5.7 vs 8.0 or 8.4 LTS) and MariaDB (such as 10.6 vs 11.4) introduce architectural syntax changes, updated default authentication plugins, and deprecated SQL functions.
Managing enterprise database clusters on an optimized performance-tuned MySQL VPS ensures you have the memory bandwidth and root control needed to execute database version migrations safely.
Method 1: Terminal Command Line Inspection
The fastest way to inspect the installed client or daemon build without logging into the database prompt is using standard terminal command flags.
Run `mysql -V` or `mysql –version` in your terminal. This prints the client distribution version, release number, and target architecture (e.g., `mysql Ver 8.0.39-0ubuntu0.22.04.1 for Linux on x86_64`).
To inspect the actual server daemon rather than the client utility, execute `mysqld -V`. This reveals the exact binary build running in the background, which is critical if multiple database client packages are installed on the same server.
For organizations running mission-critical transactional platforms, scaling to a dedicated database bare-metal server provides direct NVMe I/O performance that accelerates query processing across large database tables.
MySQL & MariaDB Version Inspection Commands
| Environment | Command / Query | Scope | Authentication Required? |
|---|---|---|---|
| Linux CLI | mysql -V | Client binary version | No login needed |
| Linux CLI | mysqld -V | Server daemon version | No login needed |
| SQL Prompt | SELECT VERSION(); | Active database engine | Yes (Database credentials) |
| SQL Prompt | SHOW VARIABLES LIKE ‘%version%’; | Full engine & OS metadata | Yes (Database credentials) |
| Package Manager | dpkg -l | grep mysql | Installed package build | No login needed |
Method 2: Interactive SQL Query Verification
If you have established an active database session or are connecting through remote database management tools (such as phpMyAdmin, DBeaver, or MySQL Workbench), SQL queries provide detailed metadata.
Executing `SELECT VERSION();` returns a single-row string containing the official version number and any vendor-specific forks (such as MariaDB or Percona Server). For broader insight, running `SHOW VARIABLES LIKE ‘%version%’;` reveals compilation comments, SSL cipher versions, and protocol details.
When planning database version upgrades or complex cross-version migrations, working with an expert Linux database administrator prevents data corruption, resolves character set mismatches, and guarantees zero downtime.
Package Manager Inspection and Operating System Repositories
In addition to runtime binary flags and interactive database prompts, verifying your database version through the Linux package manager provides essential build and security patch metadata. Package managers reveal the exact upstream distribution release, build epoch, and whether security backports have been applied by distribution maintainers.
On Debian and Ubuntu systems, running dpkg -l | grep -E "(mysql|mariadb)-server" displays the installed package version along with its architecture. On RHEL, Rocky Linux, or AlmaLinux, executing rpm -qa | grep -E "(mysql|mariadb)-server" provides equivalent comprehensive repository metadata.
Extracting Version Details via Systemd and Error Logs
When database services fail to start or cannot be accessed due to permission locks, system-level logs and systemd service controllers offer an alternative verification route.
- Systemd Service Status: Run
systemctl status mysqlorsystemctl status mariadbto inspect service binary paths and version banners logged upon initialization. - Primary Error Log Inspection: Read the first few lines of
/var/log/mysql/error.logor/var/log/mariadb/mariadb.logto identify startup version stamps. - MySQL Admin Utility: Execute
mysqladmin -u root -p versionfrom the command line to display uptime, active threads, and engine build version in a single command. - Checking Shared Libraries: Run
ldd $(which mysqld)to inspect dynamic library bindings and ensure compatibility with modern system libraries.
Version Verification via Application Runtimes: PHP, Python, and Node.js
Web developers frequently need to verify the connected database version directly from application runtimes without accessing the underlying Linux shell. Modern web frameworks provide built-in database driver inspection helpers that return database server capabilities in real time.
Querying the database server version programmatically helps applications adapt their SQL syntax dynamically, enabling advanced JSON functions or window functions only when supported by the underlying engine. This guarantees code portability across varied staging and production database tiers.
Runtime Inspection Examples
Different programming languages provide standardized methods for inspecting connected database server versions.
- PHP PDO Connection: Invoke
$pdo->getAttribute(PDO::ATTR_SERVER_VERSION);to retrieve the raw database version string for environment audits. - Python PyMySQL/MySQLdb: Access
connection.get_server_info()to verify database engine capabilities within automated deployment scripts. - Node.js mysql2 Client: Query
SELECT VERSION() AS ver;during connection pool initialization to validate database compatibility. - WordPress Environment Check: Review the Site Health dashboard under Tools -> Site Health -> Info -> Database to inspect server version, client library, and character set settings.
Auditing Database Feature Compatibility: MySQL 5.7 vs 8.0 vs MariaDB 10.x
Knowing your exact database version is especially critical when preparing for major schema upgrades or migrating between open-source database forks. Significant behavioral differences exist between legacy MySQL 5.7, modern MySQL 8.0, and corresponding MariaDB 10.x releases.
MySQL 8.0 introduced default utf8mb4 collation changes, native JSON table functions, and transactional data dictionaries that require careful pre-migration validation. Understanding your running version enables database administrators to catch deprecated features and character set incompatibilities before running production schema changes.
Key Compatibility Audit Factors
Verifying these engine capabilities ensures seamless data compatibility and prevents subtle runtime query failures across application upgrades.
- Default Collation Alignments: Confirm whether tables utilize utf8mb4_0900_ai_ci (MySQL 8.0 standard) or utf8mb4_unicode_ci to prevent collation mismatch errors during JOINs.
- Window Functions Support: Verify version support for RANK(), DENSE_RANK(), and ROW_NUMBER() analytical window functions used in reporting queries.
- Common Table Expressions (CTEs): Check if recursive and non-recursive WITH clauses are supported by the running database engine for hierarchical queries.
- Authentication Plugin Compatibility: Confirm if user accounts authenticate via caching_sha2_password or legacy mysql_native_password to avoid application connection drops.
Identifying Deprecated SQL Modes and Storage Engine Defaults
Inspecting your database version is also vital for understanding which SQL modes and default storage engines are enforced by the running binary. Newer versions of MySQL and MariaDB strictly enforce modes like ONLY_FULL_GROUP_BY and STRICT_TRANS_TABLES by default, which can cause legacy application queries to fail.
Checking your database configuration ensures you can adjust SQL mode directives in my.cnf or modernize legacy application queries to match current database standards. Understanding engine behaviors guarantees smooth software operation across future server upgrades.
- Query Active SQL Modes: Execute
SELECT @@GLOBAL.sql_mode;to identify active query restrictions and strict typing rules. - Verify Default Storage Engines: Confirm whether tables default to InnoDB or legacy MyISAM to ensure transactional ACID compliance.
- Review Deprecated Configuration Flags: Inspect startup error logs to identify deprecated directives in
/etc/mysql/my.cnfbefore upgrading. - Validate Character Set Standards: Ensure database schemas utilize
utf8mb4rather than legacy 3-byteutf8to support complete Unicode emojis and symbols.
Conclusion: Mastering Database Version Auditing in Linux
Checking the installed version of MySQL or MariaDB on a Linux server is an essential administrative task for maintaining database security, software compatibility, and peak performance. Whether inspecting binaries via CLI flags, executing interactive SQL queries, or reviewing package manager repositories, having multiple diagnostic tools ensures you can always determine your exact database build.
Accurate version tracking empowers systems engineers to schedule timely security patches, plan schema migrations, and leverage the newest performance features offered by modern database releases. Keeping your database stack properly identified and updated forms the foundation of a resilient, high-speed web hosting environment.
Frequently Asked Questions
What is the difference between mysql -V and mysqld -V?
`mysql -V` displays the version of the client command-line tool, while `mysqld -V` displays the version of the actual database server daemon that manages database storage and processes SQL queries.
How can I tell if my server is running MariaDB or MySQL?
Run `mysql -V` or log into the database shell. MariaDB explicitly includes ‘MariaDB’ in its version banner (e.g. `10.6.18-MariaDB`), whereas Oracle MySQL outputs numbers like `8.0.39` or `8.4.1` without the MariaDB moniker.
Can I check the MySQL version without root or sudo permissions?
Yes! Any standard user can run `mysql -V` from the terminal. If you have database credentials, you can log in as an unprivileged database user and run `SELECT VERSION();` to see the version string.
Why did MySQL 5.7 reach End of Life (EOL)?
Oracle officially retired MySQL 5.7 in October 2023. It no longer receives security patches, bug fixes, or performance updates. Upgrading to MySQL 8.0 or 8.4 LTS is strongly recommended to protect against known exploits.
How do I check the MySQL version using PHP code?
In PHP, you can call `$pdo->getAttribute(PDO::ATTR_SERVER_VERSION);` using PDO, or call `mysqli_get_server_info($conn);` when using the MySQLi extension to retrieve the version string programmatically.
Documenting installed database versions across your infrastructure simplifies patch cycles and prevents incompatible engine upgrades. Regular version audits ensure high query reliability and safeguard production tables against unexpected deprecation warnings.
