Solutions's picture

I am trying an installation, first created the database, then the user with full privileges, I am sure that everything is done correctly, but when accessing the database, it does not allow access.

The error is shown as:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'user001'@'localhost' (using password: YES) in /var/www/wordpress/installfolder/lib/dml/mysqli_native_moodle_database.php on line 79

 I restarted MySQL and rebooted the debian server, but no luck to make it work.

Any suggestions?


Jeremy Davis's picture

It sounds like you are fairly confident that you have set up the new MySQL user correctly, but have you double checked that you have log into MySQL with your new user?


Try logging in like this:

mysql -u user001 -p new_db_name

It should ask for your password and if everything is as it should be, you should be dropped into a mysql session. I.e. it should look something like this:

root@TEST-lamp ~# mysql -u user001 -p new_db_name
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 62
Server version: 10.5.15-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [new_db_name]>

If that doesn't work, then there is something wrong with your user or database. FWIW, this should create a new DB 'new_db_name' owned by a new user 'user001' (I set variables first so it's easy to reuse in your specific scenario - just change the first 3 lines for your purposes):

mysqladmin create "$db_name"
mysql --batch --execute "GRANT ALL PRIVILEGES ON $db_name.* TO $db_user@localhost IDENTIFIED BY '$db_pass'; flush privileges;"
mysql --batch --execute "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;"

If the above does work (or you recreate it and confirm it works) and your app still doesn't work, please double check the username and password that your app is using.

If you can confirm all the above is as it should be, then my remaining guess is some "special character" in the password (e.g. a punctuation mark) that isn't being processed properly. Perhaps retry with a long random string of "normal" characters. E.g. an mcookie:

root@TEST-lamp ~# db_pass=$(mcookie)
root@TEST-lamp ~# echo $db_pass

I hope that helps. If you continue to have issues, perhaps share more about the app you are trying to install?

Add new comment