Could not access database

Posted on

Question :

I have been trying to setup a local instance for a new application. I am new to MYSQL and I cannot understand how to actually connect this database to the actual web application sitting in the /var/www folder in my computer.

I have created a database in command line terminal:

mysql> create database mydatabase
    -> ;
Query OK, 1 row affected (0.00 sec)  

mysql> create user 'host'@'website.local' identified by 'hmypassword';
Query OK, 0 rows affected (0.00 sec)

mysql> create user 'host'@'%' identified by 'mypassword';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on database.* to 'host'@'%';
Query OK, 0 rows affected (0.01 sec)


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye


mysql -u host -h 127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 52
Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)

How to actually connect this database to the website? I also don’t understand how to make a schema for this database. Whenever I try to refresh my web browser I get the following message:

Could not access database!

SQLSTATE[HY000] [2002] Connection refused

Answer :

You create database mydatabase and then you grant on database.*
The correct is:

grant all privileges on mydatabase.* to 'host'@'%';

Leave a Reply

Your email address will not be published.