Can’t get MediaWiki to connect to MySQL using root password.

If you can not connect MediaWiki with your MySQL password and user name, do the following steps.

sudo /etc/init.d/mysql stop

Once MySQL has stopped, run:

sudo mysqld_safe --skip-grant-tables &

When MariaDB is loaded, run the following command but replace username and password with one of your choosing.

GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';

Or try to reset the root password:

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysql -uroot

when MariaDB is loaded, run the following commands but replace newpassword with the one you want.

use mysql;

press enter, then:

update user set password=PASSWORD("newpassword") where User='root';

press enter, then:

flush privileges;

press enter, then:

quit

press enter

Now stop and restart MySQL

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Try logging into MySQL

sudo mysql -u root -p

At this point you may have to add a new user if the root password will not work.

After logging into MySQL, like before, run this command:

GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';