0

I am able to create new databases through the root account. but I need to create new databases using a new user that I have created.

Here is error I'm getting when trying to create a database using the new user

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

How can I grant permissions to "user" so it create any number of new databases?

Update:

This is also what I tried:

mysql> grant all privileges on db.* to 'user'@'%' with create;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create option' at line 1
mysql>
EternallyCurious
  • 2,345
  • 7
  • 47
  • 78

1 Answers1

0

PHP example:

$con = new mysqli("...","...","..."); // CONNECT TO DB WITH ROOT USER

mysqli_query($con, "GRANT ALL PRIVILEGES ON newdb.* TO 'user'@'%' WITH GRANT OPTION");

Command line example:

login with root user, and use this:

GRANT ALL PRIVILEGES ON newdb.* TO 'user'@'%' WITH GRANT OPTION;

This will create a user how is permitted to create new databases (but will give him also all the permissions to do bad stuff, so handle it wise...).

This is for create only:

GRANT CREATE ON *.* TO 'newuser'@'%' IDENTIFIED BY 'password'
baao
  • 71,625
  • 17
  • 143
  • 203