Networking, Programming and Graphics - Tutorials
ONLINEHOWTO.net Tutorials Category

Setup a new Mysql database through command line

Type: Code Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Level: Beginner Networking, Programming and Graphics - Tutorials 
Networking, Programming and Graphics - Tutorials
Date: 2009-Jul-31
Networking, Programming and Graphics - Tutorials
Visited: 2035 times
Networking, Programming and Graphics - Tutorials
Rating: Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Published: Stephen Think

In this tutorial I will demonstrate how you can quickly create a new MySQL database using the command line interface. Most of the dedicated servers that you can buy will come with a nice web interface to manage you mysql server. Something like phpmyadmin. But in case you are building a dedicated databases server you most definitely will need to know how to set your first database from the command line.

First thing you need to do is to login into your database server. For the purposes of this tutorial I have installed mysql on a Linux server but the approach is pretty much the same even if you operate on a server with Windows operating system.

On Linux the command to enter in Mysql Command Line Interfate (CLI) is pretty intuitive.
mysql -u root -p
Just to note that the administrative username might not be root but something else. It depends on your specific installation but by default it is root.
After that you will be prompted for the root user password. Please type the password and hit Enter.

Note: if you have just installed mysql you should login with no password. That way the command is just mysql -u root

Once you are logged in you are ready to create your first database using the command line. Use the following CREATE DATABASE syntax.
CREATE DATABASE onlinehowto;

You are half-way there. We need to enter one more command and the database will be ready for use. We need to create a user for the database.
mysql > GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON onlinehowto.* TO 'user'@'localhost' IDENTIFIED BY 'password';
The database is ready for use. In case you need to manage or access your database from remote server please check this tutorial : remote connection to MySQL
Rate this tutorial:                    
Post Comment

Need a specific tutorial? Do not hesitate and submit a request!
Your e-mail: