create new MySQL database

From Petr Sladek

Jump to: navigation, search

In this tutorial Petr Sladek presents several commands to control the MySQL database management system.

The tutorial assumes that you have MySQL installed on your computer.

create new MySQL user and new MySQL database

In this tutorial Petr Sladek shows you how to create a MySQL database from the command line.

You must know the root user name (identified by <root-user-name>) and password (identified by <root-user-password>).

slady@sladek:~$ mysql -u<root-user-name> -p<root-user-password> mysql

We create a database with a name <database-name>.

mysql> create database <database-name>;

Then we create a new user to access the database. The user will have the name <new-user> and password <new-password>.

mysql> create user '<new-user>'@'localhost' identified by '<new-password>';

The last step is to grant all the privileges of the newly created database to the newly created user.

mysql> grant all privileges on <database-name>.* to '<new-user>'@'localhost';

And then we can quit back to the command line.

mysql> \q
slady@sladek:~$
Personal tools