Ben Pearce
Ben Pearce

Reputation: 7094

Switching mySQL to local server Access Denied using php script

I have been using php scripts to connect with a mySQL database on a remote server and I am trying to switch to using a local server. When I attempt to connect using the script below:

<?php
mysql_connect("localhost", "vinylpsy_singles", "password") or die(mysql_error());
mysql_select_db("vinylpsy_singles") or die(mysql_error());

$resultNew = mysql_query("SELECT * FROM `table`"); 

?> 

And am getting the following error

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'vinylpsy_singles'@'localhost' (using password: YES) in /Applications/XAMPP/xamppfiles/htdocs/chromeSave/thepopz/php/getSingles_11.php on line 2
Access denied for user 'vinylpsy_singles'@'localhost' (using password: YES)

Can any one suggest what adjustment I need to make?

Upvotes: 0

Views: 712

Answers (1)

Magnus Lindgren
Magnus Lindgren

Reputation: 287

Login as administrator on the SQL-server and run the following command:

select * from `mysql`.`user` where `user` = 'vinylpsy_singles'

Make sure there is either a line that has "localhost" in the Hosts column or the wildcard %. If neither of those are true then you have to add access to the specific user with a GRANT command. Users in MySQL are "locked" to a specific host (or wildcard).

For full GRANT use the following:

GRANT ALL PRIVILEGES ON *.* TO 'vinylpsy_singles'@'localhost'

However this privileges should of course be the same as those you used to have for your old host.

Upvotes: 1

Related Questions