mysql_connect(): Access denied for user 'root'@'localhost'

Craig Harkins

For school I have to build and basic website using PHP and MySQL. The websites function is to allow a user to register and then sign in and out. To do this, since I have no prior knowledge of PHP I was trying to follow this tutorial. I got sever space with godaddy and using MySQL I created the database called details_db. I created the files the tutorial told me and uploaded to the server. Now when I go onto the website I get these errors.

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 12

Warning: mysql_select_db(): Access denied for user ''@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 13

Warning: mysql_select_db(): A link to the server could not be established in /home/pendrive34/public_html/dbconnect.php on line 13 Connection failed : Access denied for user ''@'localhost' (using password: NO)

This is the code in the file deconnect.php

<?php

// this will avoid mysql_connect() deprecation error.
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
// but I strongly suggest you to use PDO or MySQLi.

define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'details_db');

$conn = mysql_connect(DBHOST,DBUSER,DBPASS);
$dbcon = mysql_select_db(DBNAME);

if ( !$conn ) {
    die("Connection failed : " . mysql_error());
}

if ( !$dbcon ) {
    die("Database Connection failed : " . mysql_error());
}

I've been trying to find the answer to the problem for a while but my limited knowledge is holding me back.

tanaydin

You have to write mysql root users password to

define('DBPASS', '');

this line like..

define('DBPASS', 'password_of_root_user');

If you are trying to connect a database on remote machine (like a shared hosting), you have to change DBHOST, DBUSER and DBPASS to values that given you by hosting company.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

mysql error Access denied for user 'root'@'localhost'

MySQL Error: : 'Access denied for user 'root'@'localhost'

Access denied for user 'root'@'localhost' in the mysql docker

Access denied for user 'root '@'localhost' " when connecting to mysql

MySQL said: Access denied for user 'root'@'localhost' (using password: NO)"

How to query mysql Kubernetes pod? Access denied for user 'root'@'localhost'

Rails app denied access to mysql for user root @ localhost

Mysql: Access denied for user 'root'@'localhost' right after installation on macOS

mysql how to fix Access denied for user 'root'@'localhost'

mysql (mariadb) ERROR 1698 (28000): Access denied for user 'root'@'localhost'

ERROR 1698 (28000): Access denied for user 'root'@'localhost, on MySQL 5.7

How to Solve MySQL Error: Access denied for user root@localhost

Access denied for user 'root'@'localhost' from servlet

Access denied for user 'root'@'localhost' to database 'drupal'

Access denied for user root@localhost

NodeJS/mySQL - ER_ACCESS_DENIED_ERROR Access denied for user 'root'@'localhost' (using password: YES)

Cannot connect to MySql database: ERROR 1045 (28000): Access denied for user 'root'@'localhost'

NodeJS/mySQL - ER_ECCESS_DENIED_ERROR Access denied for user 'root'@'localhost' (using password: YES)

MYSQL_ROOT_PASSWORD is set but getting "Access denied for user 'root'@'localhost' (using password: YES)" in docker container

docker-compose: Unable to connect app service to mysql database, receive "Error: Access denied for user 'root'@'localhost' (using password: YES)

ampps/Laravel5: error:Access denied for user 'root'@'localhost'

Access Denied for User 'root'@'localhost' (using password: YES) - No Privileges?

Access denied for user 'root'@'localhost' with certain passwords only

OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

error: 'Access denied for user 'root'@'localhost' (using password: YES)'

Stuck with Access Denied for user 'root'@'localhost' - Terminal, Mac

Laravel 5.4 access denied for user root@localhost on migrate

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost'