1.运用mysql建立新数据库
在shell下运行:
$>mysqladmin create database01
database database01 created.
2.启动mysql
在shell下运行:
$>mysql
welcome to the mysql monitor. commands end with ; or g.
your mysql connection id is 22 to server version: 3.21. 29a-gamma-debug
type 'help' for help.
3.更换数据库
mysql>use database01
database changed.
4.创建表
mysql>create table table01 (field01 integer, field02 char(10));
query ok, 0 rows affected (0.00 sec)
5.列出表清单
mysql>show tables;
tables in database01
table01
table02
6.列出表中的字段清单
mysql>show columns from table01;
field type null key default extra
field01 int(11) yes
field02 char(10) yes
7.表的数据填写
插入数据
mysql>insert into table01 (field01, field02) values (1, 'first');
query ok, 1 row affected (0.00 sec)
8.字段的增加
...一次一个字段
mysql>alter table table01 add column field03 char(20);
query ok, l row affected (0.04 sec)
records: 1 duplicates: 0 warnings: 0
...一次多个字段
mysql>alter table table01 add column field04 date, add column field05 time;
query ok, l row affected (0.04 sec)
records: 1 duplicates: 0 warnings: 0
注意:每一列都必须以add column重新开始。
它运行了吗?让我们看看。
mysql>select * from table01;
field01 field02 field03 field04 field05
1 first null null null
