skip to Main Content

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


  1. Correct syntax with mysql is select version();

    Fiddle

    Login or Signup to reply.
  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: %sn", mysqli_connect_error());
        exit();
    }
    
    /* print server version */
    printf("MYSQL Server version: %sn", $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%";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search