Search code examples
phpmysqlpdomysqlimysql-error-1146

PHP/PDO - Flush privileges


I'm doing some mysql server management with a script that flushes the MySQL users privileges when new privileges are added to a MySQL user.

I'm using the PDO class to do my queries, but when I do a simple

FLUSH PRIVILEGES;

I get, for

$connection->exec('FLUSH PRIVILEGES;');

and

$connection->query('FLUSH PRIVILEGES;');

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mysql.servers' doesn't exist

Is it possible to do such query with the PDO class or do I have to resort to using mysql(i)?


Solution

  • I've just tried the following portion of code :

    $dsn = 'mysql:dbname=mysql;host=127.0.0.1';
    $user = 'root';
    $password = '********';
    try {
        $db = new PDO($dsn, $user, $password);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $db->query('flush privileges;');
    } catch (PDOException $e) {
        var_dump($e);
    }
    

    And I don't get any kind of error like the one you are describing.


    Are you sure you don't have some problem with you MySQL server ?

    Your error message says that table "mysql.servers" doesn't exists... But when I look at my local MySQL server, there is such a table -- are you sure your installation/configuration is not "broken" and you didn't delete that table or anything like that ?


    BTW, it doesn't seem to be some kind of privilege you're not having : if you try to flush privileges without having the required privilege, you get the following error : "SQLSTATE[42000]: Syntax error or access violation: 1227 Access denied; you need the RELOAD privilege for this operation"