mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)
1.创建数据库
mysql> CREATE DATABASE menagerie;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| menagerie |
| mysql |
+--------------------+
3 rows in set (0.00 sec)
2.选择数据库
mysql> USE menagerie
Database changed
登录时,直接设置选择库
[root@teapot bin]# mysql -u mg -pmg menagerie
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.39-community-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
3.显示表
mysql> show tables;
Empty set (0.00 sec)
4.创建表
mysql> DROP TABLE IF EXISTS pet;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> CREATE TABLE pet
-> (
-> name VARCHAR(20),
-> owner VARCHAR(20),
-> species VARCHAR(20),
-> sex CHAR(1),
-> birth DATE,
-> death DATE
-> );
Query OK, 0 rows affected (0.01 sec)
5.描述表
mysql> describe pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)
6.插入数据
mysql> INSERT INTO pet
-> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
7.显示表信息
mysql> SHOW TABLE STATUS LIKE 'pet'\G
*************************** 1. row ***************************
Name: pet
Engine: MyISAM
Version: 10
Row_format: Dynamic
Rows: 8
Avg_row_length: 27
Data_length: 220
Max_data_length: 281474976710655
Index_length: 1024
Data_free: 0
Auto_increment: NULL
Create_time: 2009-10-10 15:00:21
Update_time: 2009-10-12 09:08:26
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
阅读(879) | 评论(0) | 转发(0) |