0

I get this error message

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

I tried to access with the root, the admin account and some user account I made for the web visitors with a few privileges. Those users (admin and web user) were created with cPanel.

I'm testing the connection with this simple code to avoid making a mess with functional code.

<?php
$con = mysql_connect("localhost","root","");
  
if (!$con)
{

die('Could not connect: ' . mysql_error());

}

 ?>

I stumbled with this explanation but it doesn't work either

Your cPanel username and password can be used to connect to your databases (as well as your cPanel). If you're connecting to your database using your cPanel username and password, you can reset your cPanel password to ensure you are using the correct username and password.

If you setup a MySQL username and password specifically for accessing a database, you'll want to ensure you are using the correct username in your php scripts. For example, MySQL usernames are always in this format:

cpanel-username_mysql-username

If your cPanel username is userna5 and you created a database username of dbuser1, then the actual database username would be:

userna5_dbuser1

Edit: i already assigned the users to a database and their privileges. I'm working on a remote server

Community
  • 1
  • 1
Progs
  • 1,059
  • 7
  • 27
  • 63

4 Answers4

1

I faced the exact same issue on one of my employees' Windows PC. The issue was caused duo the fact that his private repositories folders including those who were used by Docker were located in C:\Users{user_name} folder. At some point in time, Windows prevented Docker's access to these folders.

Solution: relocation the folders outside the Users folder solved the issue.

Itzik Shachar
  • 744
  • 5
  • 16
0

Are you running the code on your local machine or on the remote server. If it's running on your local machine you'll have to replace 'localhost' with the ip address of the server eg. '123.123.123.123'

jx12345
  • 1,650
  • 2
  • 22
  • 40
0

If you are using the online server after creating the user and the database make sure you give the user privilege to access the database

SteveTz
  • 172
  • 2
  • 8
  • If your running the code on the remote server make sure your allow your IP to access the mysql database remotely using the interface "Remote MySQL" found in cpanel to allow it, check your IP in google by typing "my ip address" – SteveTz May 22 '15 at 15:30
0

If you are accessing MySQL database from the remote server, you will have to use server IP address for MySQL host. Also you will have to allow your remote server IP address in "Remote MySQL" under your cPanel otherwise you will not be able to access your database remotely.

Kailash Aghera
  • 494
  • 3
  • 7