I’m trying to connect to my MySQL database with php, and I’m getting a http 500 error, and the following in the error log.
[Sat Aug 11 07:33:08.899904 2018] [php7:error] [pid 18763] [client 75.97.225.218:57986] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' in /var/www/html/createaccount.php:14\nStack trace:\n#0 /var/www/html/createaccount.php(14): PDO->__construct('mysql:host=127....', 'root', 'password123', Array)\n#1 {main}\n thrown in /var/www/html/createaccount.php on line 14
This is the code for createaccount.php
<?php
$host = '127.0.0.1';
$db = 'databaseDB';
$user = 'root';
$pass = 'password123';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, $user, $pass, $opt);
?>
And I can log in with mysql -u root -p and then entering the password password123. So I know it’s the password, or at least I think so, why else would it let me log in.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
The bellow steps should help you solve your problem
Once done, make sure root has all the needed privileges like so
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
You’ll need to be in MySQL to execute the above command
Regards, KDSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.