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


#1

I get the following error message when I try to create a database.

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a8995753'@'localhost' (using password: YES) in /home/a8995753/public_html/database.php on line 7

I'm using the following php code.

<?php
$con = mysql_connect("localhost","a8995753","xxxxxxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?>

While: xxxxxxxxxxxx is the password which i use to login to the domain myexp.comoj.com

Please help me to solve this error problem.


#2

Check this tutorial for more information


#3

Step 1. Login to the Members Area.
Step 2. Click on Go to Cpanel.
Step 3. Click MySQL in Software / Services section.
Step 4. Where it says MyhSQL Host copy whats underneath it example: mysql15.000webhost.com.
Step 5. Replace localhost with that.

PHP EXAMPLE:

<?php
$con = mysql_connect("mysql15.000webhost.com","a8995753","xxxxxxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?>

#4

Step 1. Login to the Members Area.
Step 2. Click on Go to Cpanel.
Step 3. Click MySQL in Software / Services section.
Step 4. Where it says MyhSQL Host copy whats underneath it example: mysql15.000webhost.com.
Step 5. Replace localhost with that.

Is it mysql15.000webhost.com or mysql5.000webhost.com?
You have mentioned mysql15.000webhost.com while in cpanle, it is mysql5.000webhost.com.

Now I'm using the following code

<?php
$con = mysql_connect("mysql15.000webhost.com","a8995753","xxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?>

and the following error messages appears.

Warning: mysql_connect() [function.mysql-connect]: Host '10.1.1.22' is not allowed to connect to this MySQL server in /home/a8995753/public_html/database.php on line 8

Please help.


#5

Hello,

The name of the database is that it appears in your control panel. G-brad wrote an example.

Another obsevación. In your free accounts you can only create two databases. The databases are created better than MySQL option from within the control panel.


#6

Hi Did you find the answer to this?

Im having the same problem.


#7

Have you double checked you have the right database name?


#8

... and database server, and database user and database password?


#9

Try this

<?php
$con = mysql_connect("mysql15.000webhost.com","a8995753_USER","YOUR PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?>

replace the "USER" <--with your username example: a8995753_admin if admin is your database username.
,"YOUR PASSWORD" <--Replace with your password.


#10

After testing your script, I found that creating database by executing php script is not
allowed in 000webhost.com server. Creating DB is possible only through MySQL icon in
your CPanel. If you want to test creating DB by executing php script, you can do it in
your localhost server as 'root' user.


#11

I test your php code and get the error:

Warning: mysql_connect() [function.mysql-connect]: Host '10.1.1.25' is not allowed to connect to this MySQL server in /home/a2475347/public_html/tmp/test.php on line 2

Could not connect: Host '10.1.1.25' is not allowed to connect to this MySQL server

What can I do?


#14

#15

Information in this topic is for deprecated cpanel. This is a tutorial for new control panel