How to create a database for an existing user in MySQL?

I want to create a database for a specific (existing) user in MySQL. How to do it?

What I tried -

CREATE USER 'myuser' @'%' IDENTIFIED BY 'mypass';
CREATE DATABASE myuser.myDatabase;

The second line is incorrect. I can not find the correct syntax.

Please tell me my mistake.

+5
source share
2 answers

when I create a user named test and create a db named test in phpmyadmin it starts:

CREATE USER 'test'@'localhost' IDENTIFIED BY  '***';

GRANT USAGE ON * . * TO  'test'@'localhost' IDENTIFIED BY  '***' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

CREATE DATABASE IF NOT EXISTS  `test` ;

GRANT ALL PRIVILEGES ON  `test` . * TO  'test'@'localhost';

it can help you.

+6
source

I tried this code. Everything seems to be in order.

CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
CREATE DATABASE mydb;

GRANT ALL 
ON mydb.*
TO myuser;
+2
source

All Articles