Create new mysql database and new user

There are two ways to create a new database in mysql. You can use mysql command if you have access to the command line or you can use graphical user interface tools. Here are examples on how to create a new database in mysql using command line and gui tools:

Create a new database using mysql command

1) Login into mysql as root.

[email protected]:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.0.75-0ubuntu10.5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

2) Create a new database using mysql 'create database' command.

mysql> create database newdb;
Query OK, 1 row affected (0.00 sec)

That's it. Now you have a new database created for root user. If you want to use other user than root to manage the database, then you can create a new user and assign privileges to the database. Here is the steps:

1) Login into mysql as root.

2) Create user as well as grant privileges.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'drupal'@'localhost' IDENTIFIED BY 'passwd1';
Query OK, 0 rows affected (0.00 sec)

Create a new database using phpmyadmin

You must have PHPMYADMIN installed in your system before performing these steps. Here are steps to create a new database using phpmyadmin:

Open web browser. Type localhost/phpmyadmin in the url and press enter.

phpmyadmin enter url image

Login using the database admin user and key in the correct password.

phpmyadmin login page image

Create a new database.

phpmyadmin create new database image

Add new user and assign privileges for the new user to manage database.

1) Click Privilege menu.

phpmyadmin privilege menu image

2) Click Add a new user link to add a new user for mysql database.

phpmyadmin add new user image

3) Fill login information for a new mysql database user account.

phpmyadmin set mysql new user login information image

4) Set privileges for the new mysql database user.

phpmyadmin set global privileges image

5) Set specific privileges for the new mysql database user if you want.

phpmyadmin set global privileges image

6) Select specific privileges for the new mysql database user.

Image

That's all. Now you have a new database and a new user with specific privileges to manage the database.

Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.