1、选择要操作的数据库
命令:USE dbname
mysql> USE java407 Database changed
2、查看要操作的数据库中的所有数据表
命令:SHOW TABLES;
mysql> SHOW TABLES; Empty set (0.00 sec)
3、创建数据表
命令:
mysql> CREATE TABLE users ( -> id INT(10) NOT NULL AUTO_INCREMENT, -> username VARCHAR(16) NOT NULL, -> password VARCHAR(16) NOT NULL, -> sex CHAR(2) NOT NULL, -> age INT(3) NULL, -> birth DATE NULL, -> PRIMARY KEY(id)); Query OK, 0 rows affected (0.69 sec)
4、查看要操作的数据库中的所有数据表
命令:SHOW TABLES;
mysql> SHOW TABLES; +-------------------+ | Tables_in_java407 | +-------------------+ | users | +-------------------+ 1 row in set (0.00 sec)
5、查看数据表定义
mysql> DESC users; +----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+----------------+ | id | int(10) | NO | PRI | NULL | auto_increment | | username | varchar(16) | NO | | NULL | | | password | varchar(16) | NO | | NULL | | | sex | char(2) | NO | | NULL | | | age | int(3) | YES | | NULL | | | birth | date | YES | | NULL | | +----------+-------------+------+-----+---------+----------------+ 6 rows in set (0.00 sec)