MySQL Getting Started Guide-quick reference (2) II. MySQL User Guide
1. use MySQL to create a new database
Run in shell:
$> Mysqladmin create database01
Database "database01" created.
2. start MySQL
Run in 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. change the database
Mysql> use database01
Database changed.
4. create a table
Mysql> create table table01 (field01 integer, field02 char (10 ));
Query OK, 0 rows affected (0.00 sec)
5. list tables
Mysql> show tables;
Tables in database01
Table01
Table02
6. list fields in the table
Mysql> show columns from table01;
Field Type Null Key Default Extra
Field01 int (11) YES
Field02 char (10) YES
7. enter data in the table
Insert data
Mysql> insert into table01 (field01, field02) values (1, 'first ');
Query OK, 1 row affected (0.00 sec)
8. add fields
... One field at a time
Mysql> alter table table01 add column field03 char (20 );
Query OK, l row affected (0.04 sec)
Records: 1 Duplicates: 0 Warnings: 0
... Multiple fields at a time
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
Note: Each column must start again with "add column.
Is it running? Let's take a look.
Mysql> select * from table01;
Field01 field02 field03 field04 field05
1 first NULL