Home > Software design >  WordPress MySQL database connection error when restoring dump
WordPress MySQL database connection error when restoring dump

Time:03-04

I want to dump and restore a WordPress database hosted in Azure for MySQL using mysqldump/mysql. Here are the steps I have followed:

I dumped database named wordpress:

mysqldump.exe -Fc -v --column-statistics=0 -h host -u user -p -d wordpress > wordpress_backup.sql

then I removed the database:

drop database wordpress;

then I created the database:

create database wordpress;

and then, I restored the dump to the database:

mysql.exe -h host -u user -p wordpress < wordpress_backup.sql

After this process, WordPress is unable to connect to the database, leading to this error: Error

I have checked that database engine is InnoDB and also tried different charset/collation combinations (to match WordPress config) but none of these work.

What could be the reason for this?

CodePudding user response:

Have you verified that the user accessing this database has permissions?

SHOW GRANTS FOR 'user'@'localhost';

or maybe you can put this code at the first lines of your wp-config.php with the data connection for your database (host, user and pass). If not connected, the code shows the reason for the connection error

<?PHP
    $link = mysqli_connect('localhost', 'username', 'password');
    if (!$link) {
        die('Could not connect: ' . mysqli_error());
    }
    echo 'Connected successfully';
    mysqli_close($link);
?>

CodePudding user response:

The problem was I left -d tag at the end of mysqldump command, which means data is not included in the dump. From official documentation:

--no-data, -d

Do not write any table row information (that is, do not dump table contents).
This is useful if you want to dump only the CREATE TABLE statement for the 
table (for example, to create an empty copy of the table by loading the dump file).
  • Related