Creating a MySQL database via the command line

Categories:

So you followed the MySQL 5 installation guide and have MySQL installed and ready to go. The next step will be to create a user and database so you can start using MySQL, and in this guide we'll show you how the basics of how to create a database on your Windows based system. There are many ways to do this as there are a lot of support tools out there for MySQL. In this guide though we'll stick to the basics and show you how to add a database using the MySQL command line client.

The MySQL command line client provides you with a means of interacting with your MySQL server from the command line (duh!), and is installed as a part of the MySQL Server installation process. GUI clients tend to be favoured these days, but it is important to become familiar with the MySQL command line client syntax as it is very useful for automation of important tasks such as backups (not covered in this guide).

  • Start the MySQL command line client by selecting the MySQL Command Line Client item from your MySQL program group in your start menu.
  • The MySQL command line client will prompt you for the root password. Enter it and push enter.
  • To create a database simply type in;
CREATE DATABASE testdb;

  • This will create a database called testdb. Simply replace testdb with the name you want to call your database.
  • Finally, lets verify that the database has been created. Type in;
SHOW DATABASES;

  • This will list all the databases on your server, and you'll see our testdb database listed.
  • Refer to figure 1 below to see an example of the MySQL command line output you would expect to see by running these commands.


figure 1

That is it, you now have a database using all the server default values ready to use. If you wish to create the database using values other than the default, our would like to read about additional options then I suggest you have a read of the CREATE DATABASE syntax documentation on the MySQL site.

Average rating
(12 votes)

Comments

Anonymous's picture

AWESOME dude...I NEEDED THIS

AWESOME dude...I NEEDED THIS SO!!! BAD

Anonymous's picture

thanks...

thanks...

Anonymous's picture

needed help in this

I have tried this but it is just closing the command window without saying anything . Is that i am entering a wrong password? But i havn't changed the password when i installed it so the default password will be "adminadmin" if i am not wrong.
Can you help me in this ?

Brashquido's picture

Reset the root password

There is no way I can tell you what your root password is for MySQL, so the easiest thing to do from here is to manually reset it by following these instructions. Let me know if you're still having issues.

----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

thanks its works great

thanks its works great

Anonymous's picture

Resolving mysql cmd

I can not create nor show database after changing to the path of sql directory where my files are located using the Xampp software,because it tells me the command is not valid as an internal or external command when i type mysql on the command line.
Can someone help me on this issue.

From Chuck

Anonymous's picture

Thanks

Thanks so very much,av been looking for this

Anonymous's picture

Thank you

This guide was just what i needed, being new to MYSQL i coulf not figure out how to create a data base, found this awsome :) wish i found this guide last nigth would not of been up till 4am :)

Anonymous's picture

Great it works Thanks

Great it works Thanks

Anonymous's picture

Many Thanks Man

I've been looking for this so bad, you just saved my a** bru, thanks!