Monday, June 29, 2009

Creating a database in MySQL

While you can use a GUI such as MySqlWorkbench that works with MySQL to create a database, you can also use the command line to create a database.

The MySQL used in the present case is the version that came with a recent XAMPP download. XAMPP is an easy to install Apache distribution that brings with it MySQL, PHP and many others. The one I used is a Windows distribution which contains many other programs. Presently I am using only the Apache and MySQL. Here is a XAMPP Control Panel that I use often. As I also have a IIS5.1 running on the same machine (at default port 80), I have to use one (Apache) or the other (IIS) at any given time. It is very easy to stop and start as you can see in the control panel.




In my previous post I described how you may connect to the database from your DOS window.

Here is the login command and the 'Show Databases' command to review the databases on this server:
----------

C:\xampp\mysql>cd bin

C:\xampp\mysql\bin>mysql -h localhost -u root -p
Enter password: *********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.1.30-community MySQL Community Server (GPL)


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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cdcol              |
| expacc             |
| mengerie           |
| mydb               |
| mysql              |
| phpmyadmin         |
| test               |
| webauth            |
+--------------------+
9 rows in set (0.00 sec)

mysql>
-----------------------------
To create a new database (TestDemo) is easy as you see in this command:
mysql> create database TestDemo
    -> ;
Query OK, 1 row affected (0.05 sec)

mysql>
--------------------------
If you run the Show Databases again, you will see the new database (of course it will be empty) as in the following:

mysql> Show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cdcol              |
| expacc             |
| mengerie           |
| mydb               |
| mysql              |
| phpmyadmin         |
| test               |
| testdemo           |
| webauth            |
+--------------------+
10 rows in set (0.08 sec)


mysql>
--------
You do a quit when you want to get out as in:
mysql> quit
Bye

C:\xampp\mysql\bin>

No comments:

DMCA.com Protection Status