saving . . . saved getting database connection failed has been deleted. getting database connection failed has been hidden .
getting database connection failed
Title
Question

 I am getting the following error while installing moodle can u please give the solution.


Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php



Warning<span style="color: rgb(185, 74, 72); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; background-color: rgb(242, 222, 222);">: mysqli::__construct(): (HY000/1045): Access denied for user 'moodle-st'@'localhost' (using password: YES) in </span>C:\moodle\server\moodle\lib\dml\mysqli_native_moodle_database.php<span style="color: rgb(185, 74, 72); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 14px; background-color: rgb(242, 222, 222);"> on line </span>79

Moodle-Learning-Management-System Installing-Moodle-on-Local-Server 04-05 min 0-10 sec 29-04-20, 6:11 p.m. ekta.naik@vcet.edu.in

Answers:

The error says 'Access denied for user 'moodle-st'@'localhost' (using password: YES)'

A few points to be taken into consideration are:
- Have you entered the password for the database user 'moodle-st' correctly while entering database info during installation?
- And is the user 'moodle-st' granted with the correct permissions for the moodle database?

Solution can be -
You can try creating a new database user and a new db as well.
Commands for Ubuntu OS -
1] Login to mysql as a 'root' user. In terminal type: sudo mysql -u root -p 
Enter root password.

2] If not created already, or since you are at an initial phase, you can create database afresh for Moodle:
mysql> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

3] Create a user/password combination with appropriate permissions for the database:
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'yourpassword';

4] Exit from mysql.

Now, continue with Moodle installation and enter the details for database as set above:
Database: moodle
Database user: moodleuser
Db password: yourpassword

For Windows:
You need to create a database and a database user first.
- Go to http://localhost/moodle. The language select page should come up and you are away. 
- Data directory is C:\moodledata (or whatever you created)
- Database is 'moodle' (name of the database you created)
- Database user is 'root' (unless you created a more restricted user as shown above for your system)
- Database password is whatever you set installing MySQL

Helpful links for Windows OS-
- https://docs.moodle.org/38/en/Complete_install_packages_for_Windows#Database_configuration
- https://docs.moodle.org/38/en/Manual_install_on_Windows_7_with_Apache_and_MySQL#Step_7:_Install_Moodle

If you are still facing issues after this, please send screenshots of the error if possible.

A few helpful posts from Moodle forums:
- https://moodle.org/mod/forum/discuss.php?d=340330
- https://moodle.org/mod/forum/discuss.php?d=163173
- https://stackoverflow.com/questions/39094107/moodle-database-connection-failed

You can also check the database details in config.php file (if it has been generated) located at C:\moodle\server\moodle\config.php.

Please let me know if you have any further issues.
29-04-20, 7:30 p.m. kashmira.n


A few more helpful links - 
- https://docs.moodle.org/38/en/Windows_installation_using_XAMPP#Option_create_the_database
- https://docs.moodle.org/38/en/Installation_quick_guide#Create_a_database

A few older version docs which might give you some ideas - 
- https://docs.moodle.org/20/en/Create_Moodle_site_database
- https://docs.moodle.org/20/en/Windows_installation_using_XAMPP#Create_the_MySQL_database

30-04-20, 10:41 p.m. kashmira.n


Log-in to answer to this question.