Access denied to mysql through php
20nation said 1 year ago:
I’m trying to connect to my mysql database through php but every time I try I get this error:
Could not connect: Access denied for user ‘tango8888′@’%’ to database ‘tango8888_game’
I can’t figure out why it’s doing this.
Gary A said 1 year ago:
@20nation
When connecting to your database, you should keep in mind that the database username will be the same as the database name. You also might want to try resetting the password for your database. Information on resetting your password can be found here:
http://support.godaddy.com/help/3310/resetting-your-mysql-database-password
-Gary
20nation said 1 year ago:
I tried that and making new databases but none of it is working. Here is the script I am running maybe there is something wrong with it.
<?php
$dbc = mysql_connect(“tango8888.db.9343059.hostedresource.com”,”tango8888″,”password”);
if (!$dbc)
{
die(‘Could not connect: ‘ . mysql_error());
}
//select database
?>
<?php
$db_selected = mysql_select_db(“tango8888_game”, $dbc);
if (!$db_selected)
{
die(‘Could not connect: ‘ . mysql_error());
}
//test
if (mysql_query(“CREATE DATABASE my_db”,$con))
{
echo “Database created”;
}
else
{
echo “Error creating database: ” . mysql_error();
}
mysql_close($con);
?>
Gary A said 1 year ago:
@20nation
Are you receiving the error when trying to connect to the database, or are you able to connect to the database and then receive an error once connected? Based on the information you provided, it looks like you are trying to run the CREATE DATABASE command. The Database is already created, so using this command will result in an error. Additionally, our database servers do not support programmatically creating databases. You will want to ensure that you have properly created the database through your hosting account. This article explains how you can create a database:
http://support.godaddy.com/help/article/36
-Gary
20nation said 1 year ago:
When I run the php script it just says: Could not connect: Access denied for user ‘tango8888?@’%’ to database ‘tango8888_game’. But I have used other mysql commands that was just one i was trying to see what was wrong. Here’s another script that gets the same problem.
<?php
//opens connection to mysql server
$dbc = mysql_connect(‘crazycraka.db.9343059.hostedresource.com’,'crazycraka’,'password’);
if (!$dbc) {
die(‘Not connected:’ . mysql_error());
}
//select database
$db_selected = mysql_select_db(“crazycraka_game”, $dbc);
if (!$db_selected)
{
die (“cant connect :” . mysql_error());
}
//test
$query=”INSERT INTO crazycraka.game
(id, points, rating, age) VALUES (‘Mike’, ’3′, ’1′, ’21′)”;
$result=mysql_query($query);
?>
Gary A said 1 year ago:
@20nation
Based on what you have provided, it looks like you are using the wrong database name in your script. If the user name of your database is crazycraka, then you should be using this same name when you select the database in your script. The username for the database connection and the name of the database will always be the same. You can find an example of a connection string here:
http://support.godaddy.com/help/3351/mysql-connection-string-with-php
-Gary
20nation said 1 year ago:
Wow good eye, it worked. Thank you for your help
Gary A said 1 year ago:
@20nation
Glad I was able to help out. If you have any other questions, please feel free to post them on the Forums
-Gary
5 min expected wait time