1

Using either a SQL query, or some php code, how can I determine which version of MySQL is running. I found several examples of using the command line, but I need to check programmatically.

I tried

SELECT @version;

But that returned NULL.

I did search stack overflow, and found a lot of questions, but they were about other dbs or programming languages. I didn't find any specifically for MySQL.

2 Answers 2

2

You can get by user mysqli_server_info or the oop way using $mysqli->server_info;

<?php

$mysqli = new mysqli("localhost", "my_user", "my_password");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* print server version */
printf("MYSQL Server version: %s\n", $mysqli->server_info);

$mysqli->close();

Or in MYSQL Query way

SELECT VERSION();

Or you may want to show in detailed way

SHOW VARIABLES LIKE "%version%";
Sign up to request clarification or add additional context in comments.

Comments

1

Correct syntax with mysql is select version();

Fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.