创建MySQL示例数据库的过程(menagerie)
相关脚本:http://downloads.mysql.com/docs/menagerie-db.zip
1、建立并连接db
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -h localhost -u root -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database menagerie;
Query OK, 1 row affected (0.00 sec)
mysql> use menagerie ;
Database changed
2、下面建立Pet表,同时加载数据
mysql> LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;Query OK, 8 rows affected (0.06 sec)
Records: 8 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from pet;
+----------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+--------+---------+------+------------+------------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
+----------+--------+---------+------+------------+------------+
8 rows in set (0.00 sec)
通过脚本增加一个新的记录
mysql> SOURCE ins_puff_rec.sql
Query OK, 1 row affected (0.06 sec)
3、下面建立event表,同时加载数据
mysql> SOURCE cr_event_tbl.sql
Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK, 0 rows affected (0.09 sec)
mysql> LOAD DATA LOCAL INFILE 'event.txt' INTO TABLE event;
Query OK, 10 rows affected, 2 warnings (0.06 sec)
Records: 10 Deleted: 0 Skipped: 0 Warnings: 2
mysql> select * from event;
+----------+------------+----------+-----------------------------+
| name | date | type | remark |
+----------+------------+----------+-----------------------------+
| Fluffy | 1995-05-15 | litter | 4 kittens, 3 female, 1 male |
| Buffy | 1993-06-23 | litter | 5 puppies, 2 female, 3 male |
| Buffy | 1994-06-19 | litter | 3 puppies, 3 female |
| Chirpy | 1999-03-21 | vet | needed beak straightened |
| Slim | 1997-08-03 | vet | broken rib |
| Bowser | 1991-10-12 | kennel | NULL |
| Fang | 1991-10-12 | kennel | NULL |
| Fang | 1998-08-28 | birthday | Gave him a new chew toy |
| Claws | 1998-03-17 | birthday | Gave him a new flea collar |
| Whistler | 1998-12-09 | birthday | First birthday |
+----------+------------+----------+-----------------------------+
10 rows in set (0.00 sec)
贸易电子化,技术全球化