Access denied for user when trying to create new database

Access denied for user when trying to create new database.

I make connection to MySQL server and i then try create new database, grant privileges to user on new database but i cant even create the database...

What am I doing wrong?


<?php
require_once('functions.php');
 
$handshake = $functions->OpenConnection();
 
$query = 'CREATE DATABASE IF NOT EXISTS hilomaster';
mysql_query($query) or die(mysql_error());
	
$query = 'GRANT INSERT,SELECT,UPDATE,DELETE ON hilomaster TO hilo@hilomaster';	
mysql_query($query) or die(mysql_error());
 
mysql_select_db('hilomaster') or die(mysql_error());
		
$functions->CloseConnection($handshake);
?>

Open in new window

LVL 16
ellandrdAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
you need the grant the CREATE permission to Create the database to that login BEFORE letting that user create the db:
http://dev.mysql.com/doc/refman/5.0/en/create-database.html

grant syntax reference:
http://dev.mysql.com/doc/refman/5.0/en/grant.html

0
 
ellandrdAuthor Commented:
Morning angelIII, congrats on the Elite rank btw!!

Right so what you saying is I have to grant privilege to my username onmy new database, before i can create my new database?  that doesnt seem right?  How cxan i grant CREATE for example on a database that doesnt exist yet or have i misunderstood you?

Ellandrd
0
 
ellandrdAuthor Commented:
So....

$query = 'GRANT INSERT,SELECT,UPDATE,DELETE ON hilomaster TO hilo@hilomaster';  
mysql_query($query) or die(mysql_error());
 
$query = 'CREATE DATABASE IF NOT EXISTS hilomaster';
mysql_query($query) or die(mysql_error());

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the problem is that you cannot grant the permissions to "yourself".
so, either you HAVE the permissions to create the database, or you don't
if you have it, you can create the database, if you don't you cannot grant the permission to yourself.

you will need to grant that permission (CREATE) using root account, for example.
0
 
ellandrdAuthor Commented:
I have logged into my cPanel account and checked the permissions that my user account has on the MY SQL Server.  I have ALL privileges but yet i cant create a new database
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what is the exact error you get, actually?
0
 
ellandrdAuthor Commented:
Access denied for user 'hilo'@'hilomaster' (using password: YES)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
on which statement?
0
 
ellandrdAuthor Commented:
i get it on both statements.  i switched statements around and tried both...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
can you please indicate the code of:
$functions->OpenConnection() ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.