HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to grant database creation privilege to a user in MySQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
privilegeusergrantdatabasemysqlhowcreation

Problem

Following command provides all privilege in all databases for User 'admin'. But it doesn't allow 'admin' to create database.

GRANT ALL ON * . * TO 'admin'@'localhost';


How can I provide the access for 'admin' to create database?

As I am trying to Create database, I am getting the following error -


ERROR 1044 (42000): Access denied for user 'admin'@'localhost' to
database 'newdb'

Solution

ALL privileges includes "ALL" of them except "wITH GRANT OPTION"... Thus above command will let admin user create the database too.

You might want to show the error that you're getting. Note that in above GRANT you have not specified the password for admin user too.

Update:

You should be able to do following:

login as root and create user:

$] mysql -uroot -p
mysql> grant all privileges on *.* to 'admin'@'localhost';


login as admin (without password):

$] mysql -uadmin -p
mysql> create database admin;


When you login, you can verify your privileges as follows:

mysql> show grants;

or

mysql> show grants for current_user();

mysql> select current_user() will show you, user you logged in as.

Code Snippets

$] mysql -uroot -p
mysql> grant all privileges on *.* to 'admin'@'localhost';
$] mysql -uadmin -p
mysql> create database admin;

Context

StackExchange Database Administrators Q#114837, answer score: 7

Revisions (0)

No revisions yet.