|
Introduction to MySQL
Part:
1
2
This chapter describes:
- What's in MySQL?
- How to use the SQL client tool - mysql.
- How to dump data into files.
- How to load data from files back to tables.
What's in MySQL?
Programs and tools offered in MySQL:
- mysqld - MySQL server daemon.
- mysqladmin - Administrator tool, command line based.
- mysql - SQL client tool, command line based.
- mysqlimport - Tool to load data into tables from text files.
- mysqldump - Tool to dump data of the an entire database.
- mysqlcheck - Tool to check and repair databases.
- mysqlmanager - SQL client tool, GUI based.
Using the SQL Client Tool - mysql
mysql is very easy to use:
- To launch mysql, run "\mysql\bin\mysql --host hostName databaseName".
- To run any SQL statement, enter "sqlStatement;". The last character,
";", triggers mysql to execute the statement on the server.
- To quit from mysql, enter "quit".
- To get help, enter "help".
In the following example, I executed 4 SQL statements with mysql:
\mysql\bin\mysql --host localhost test
......
mysql> create table hello (message varchar(80));
Query OK, 0 rows affected (0.41 sec)
mysql> insert into hello (message) values ('Hello world!');
Query OK, 1 row affected (0.03 sec)
mysql> select * from hello;
+--------------+
| message |
+--------------+
| Hello world! |
+--------------+
1 row in set (0.00 sec)
mysql> drop table hello;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
Note that:
- The official name of mysql is MySQL Monitor.
- mysql reports you back on the execution time of each statement.
- Result of the SELECT statement is nicely formatted.
In the previous example, SQL statements were executed interactively one by one.
Another way to execute SQL statements is to put them into a file, and execute them
in one command. First let's all the statements we used in the previous into a file,
hello.sql:
-- hello.sql
-- Copyright (c) 1999 by Dr. Herong Yang
--
create table hello (message varchar(80));
insert into hello (message) values ('Hello world!');
select * from hello;
drop table hello;
(Continued on next part...)
Part:
1
2
|