0

I am a mac user and so only have access to the mac terminal.

I am developing a database driven website, I'm trying to connect to the database but keep getting this error which I don't know how to fix.

My php code is:

    $connection = mysqli_connect("MY IP ADDRESS HERE","root","","coursework")   

but when opening the browser I get the following message:

Warning: mysqli_connect(): (HY000/1130): Host '192.168.64.2' is not allowed to connect to this MariaDB server in /opt/lampp/htdocs/functions/db.php on line 2

Does anybody know how I can allow connection to this database? Thank you in advance

R B
  • 658
  • 4
  • 12
  • 1
    I've never used MariaDB but a Google search for your error came up with https://stackoverflow.com/questions/43124641/not-allowed-to-connect-to-this-mariadb-server-in-php – Darren Apr 03 '18 at 10:55
  • maybe your ip-address is not given in the configuration of your sever and/or the option _bind-address_ is set so that your connection can't be established using your IP. try it with _localhost_ instead or check your configuration file of MariaDB (which should be my.cnf somewhere on your system; e.g. /etc/) for that issue. – meistermuh Apr 03 '18 at 10:55
  • Possible duplicate of [Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server](https://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server) – Philipp Maurer Apr 03 '18 at 11:26

2 Answers2

0

Possibly a security precaution. You could try adding a new administrator account:

mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
->     WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
->     WITH GRANT OPTION;
0

It looks like you don't have necessary permission to access your database through a script. You need to open up connection to your database. Use the following SQL query and execute it.

GRANT ALL PRIVILEGES ON coursework.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
  • coursework.* means all tables of database 'coursework'.
  • root@'%' means access to root coming from any IP.
  • Replace password with your MySQL password.

Side note: Don't use root to access MySQL server from PHP. Create a user instead. Hope it helps.

Haseeb Jehanzeb
  • 319
  • 5
  • 9