|
My SQL Part 2 - Basic SQL - Page 3 Before you can use the MySql database, you will need to know how to enter commands using the MS dos prompt. |
||
|
MS DOS On my computer the MS dos program is located at: C:\Windows\command.com So I suggest you create a shortcut to the command.com program. When you run the program, you will see the following prompt: C:\WINDOWS> Which means that it is addressing the 'Windows' directory. |
||
|
CHANGE DIRECTORY Since MySql is located at C:\mysql\bin you will need to change to that directory. So type at the command prompt: C:\WINDOWS> cd c:\mysql\bin The prompt will change as follows: C:\mysql\bin> |
||
|
RUNNING MYSQL Type at the prompt: C:\mysql\bin> mysql And you will see: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 4.0.18 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> To return to the MS dos prompt, type 'quit'. |
||
|
SHOW DATABASES Type at the prompt: mysql> show databases; And you will see the databases, which already exist:
2 rows in set (0.17 sec) If you forget to type ';' at the end of a statement, you will see the following prompt: --> To return to the 'mysql' prompt, type ';' For example: -> ; mysql> |
||
|
STRUCTURED QUERY LANGUAGE The first SQL command was 'show databases;'. Now it is time to use some more: mysql> use mysql; Database changed mysql> The syntax is "use database-name;" which means the name of the database. The name of this database, just to confuse you, is 'mysql'. So in other words, you are using a database called 'mysql'. |
||
|
SHOW TABLES Before you can show the tables in a database, the database has to be selected first. Otherwise, you will see: ERROR 1046: No Database selected So starting from the beginning: mysql> use mysql; Database changed mysql> show tables; You will see a list of the tables in the 'mysql' database.
6 rows in set (0.06 sec) |
||
|
EXPLAIN TABLE NAME One of the tables is called 'user'. So type at the prompt: mysql> explain user; And the screen will fill up with a load of useless information. The syntax is "explain table-name;", the table-name is 'user', so you type "explain user;" You can, of course, explain any of the tables, and "explain db;" will produce a better example. |
||
|
CREATE DATABASE The syntax is "create database database-name;", the database-name is 'idiots', so you type "create database idiots;" mysql> create database idiots; Query ok, 1 row affected (0.05 sec) If the database already exists, you will see: ERROR 1007: Can't create database 'idiots'. Database exists mysql> |
||
|
SHOW DATABASES Type at the prompt: mysql> show databases; And you will see the database 'idiots', added to the list:
3 rows in set (0.05 sec) |