Solved

Access denied for user when trying to create new database

Posted on 2008-10-12
10
225 Views
Last Modified: 2013-12-13
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

0
Comment
Question by:ellandrd
  • 5
  • 5
10 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22696821
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
 
LVL 16

Author Comment

by:ellandrd
ID: 22696855
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
 
LVL 16

Author Comment

by:ellandrd
ID: 22696857
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22696882
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
 
LVL 16

Author Comment

by:ellandrd
ID: 22696887
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22696923
what is the exact error you get, actually?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 22696943
Access denied for user 'hilo'@'hilomaster' (using password: YES)
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22696989
on which statement?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 22697267
i get it on both statements.  i switched statements around and tried both...
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22698355
can you please indicate the code of:
$functions->OpenConnection() ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now