|
MySQL is a very powerful open source database which means that it is free to use. One of the many tools that come with MySQL is their MySQL Command Line that will allow you to do pretty much everything from create a database to add and edit entries in the database. This article will help you to begin using MySQL Command Line Successfully. When you install MySQL you will receive a command line application where you can create new databases, modify current databases, and delete databases. Once you launch the MySQL Command Line Client you will be prompted for a password assuming you set one up when you installed MySQL. From here you will be given a mysql> prompt and you will be able to enters your commands.
Lets start with creating a database in our system:
mysql> CREATE DATABASE temp; Query OK, 1 row affected (0.00 sec)
Be sure that when creating databases, tables, and fields that the names are case sensitive and cannot include spaces. All commands issued through the command line must end with a semi-colon (;) or else you will be promtped for more commands.
In order to edit this new database we have created we need to switch to it and that is where the USE command comes into play.
mysql> USE temp; Database changed
Now that we have a working database lets create a table in the database to store our relatives
mysql>CREATE TABLE family (name char(25), age integer, relation char(50)); Query OK, 0 rows affected (0.05 sec)
We just created a table that contains three fields so lets go into a little more detail about that command we just ran.
First we used the CREATE TABLE command which does exactly what it says does and it creates the table. Where we typed in family is the name of the table that we just created. Everything else within the parenthasis are fields in the table and what type of information is going to be stored in that field. For example that name char(25) tells SQL to create a field within the table called "name" and the char(25) tells it that it will be a character field meaning you can type any character you want in it and that it is 25 characters long. The age integer tells SQL to create a field in the table called age and that it will be a integer meaning that only whole numbers are stored in this field. You can add a size to the integer field like when using char but it is not nessecary as the default length of an interger field is 11. The last one is just like the first one realtion char(50) except for the fact that we made this field able to hold 50 characters instead of 25.
Now that we have created a database and a table lets look at a coupld show commands to see what we have. The show commands are pretty straight forward in terms of what they do. Lets start with SHOW DATABASES; |