Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access denied for user @ 'localhost' to database '' [closed]

Tags:

I'm seeing a lot of of similar questions to this. but can't find one exactly like mine yet. Not sure where to change these settings or anything, any help appreciated.

access denied Access denied for user ''@'localhost' to database ''

This is the beginning of my page.

$dbhost = 'localhost'; //unlikely to require changing.
$dbname ='publication'; //modify these
$dbuser = 'username'; //variables 
$dbpass = ''; //// to your installation
$appname = 'application name'; // and preference

mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
like image 655
expiredninja Avatar asked Dec 23 '11 23:12

expiredninja


People also ask

How do I fix localhost Access Denied?

Use the ALTER USER command and change the authentication method to log into MySQL as root: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password'; This command changes the password for the user root and sets the authentication method to mysql_native_password.

How do I fix MySQL access denied error?

You will get this error when the user user_name does not have the right to access your MySQL database. To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password';


2 Answers

Try this: Adding users to MySQL

You need grant privileges to the user if you want external acess to database(ie. web pages).

like image 115
gama_jr Avatar answered Sep 24 '22 16:09

gama_jr


You are most likely not using the correct credentials for the MySQL server. You also need to ensure the user you are connecting as has the correct privileges to view databases/tables, and that you can connect from your current location in network topographic terms (localhost).

like image 30
Clay Freeman Avatar answered Sep 23 '22 16:09

Clay Freeman