2

It is the first time I upload a web page to a server and I am quite inexperienced in the subject. I downloaded xampp to work in a production environment and through phpmyadmin I configured a user name, password and host = '%' But when I upload my files with Filezila, I throw this:

SQLSTATE [HY000] [1045] Access denied for 'user' @ 'localhost' (using password: YES)

I tried to connect to my server through the Mysql Shell and Workbench to create a user "user" that had all the permissions to access my database, but in both cases I threw the following:

Host xxxx.xx.xx Is not allowed to connect to this MariaDB server.

What I do not understand is why MariaDB Server? I do not have it downloaded or something.

I do not really know how I can grant the permissions to the new user inside the host so that it can access my database. My connection code is as follows:

try {   
    $dsn = 'mysql:host=%;dbname=db_name;charset=utf8';
    $db = new PDO($dsn, 'user', 'contraseña');
    $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}
cosinepenguin
  • 1,545
  • 1
  • 12
  • 21

3 Answers3

2

1)For the first error, it is saying that your mysql credentials are invalid. Correct your database configuration in your php code. Arrange the username, password, etc... You can get this info from your hosting provider. Try to change '%' to 'localhost'.

2)For the second Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server and

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;

FLUSH PRIVILEGES;
Michael GEDION
  • 879
  • 8
  • 16
  • Thanks for your answer! I have changed the username, and password (those provided by my hosting provider) in phpmyadmin, in the console (the second problem is solved, thanks!) and in my php code, and I have left both the host as localhost, but the error persists. – Miguel Sánchez García Jul 25 '17 at 04:59
  • @Michael, edit your answer to prevent clogging up the comment replies on your answer. – Option Jul 25 '17 at 06:44
  • `ALTER USER 'userName'@'localhost' IDENTIFIED BY 'New-Password-Here';` helped since I did not set a password. then grant privileges and flush. – mamesaye May 01 '19 at 21:15
1

For the first issue:If your server name is localhost. Please verify all o f the info (servername, username, password for database) from your hosting provider. Try this code:

<?php

$servername = "localhost";
$username = "yourusername";
$password = "yourpassword";

try {
    $conn = new PDO("mysql:host=$servername;dbname=yourdatabase", 
    $username, $password);
   // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
catch(PDOException $e)
    {
        echo "Connection failed: " . $e->getMessage();
    }
?>
Michael GEDION
  • 879
  • 8
  • 16
0

MariaDB is a fork of MySQL, many hosting providers and linux distributions have MariaDB by default. Using MariaDB is quite the same as MySQL. Note that in your connection string the host is typically localhost instead of %.

Sal
  • 1,307
  • 1
  • 8
  • 16