用 MySQL 创建数据库和数据表:步骤:1、使用 show 语句找出在服务器上当前存在什么数据库:mysql>show databases;2、创建一个数据库 test:mysql〉create database test;3、选择你所创建的数据库:mysql〉use test;4 创建一个数据表:首先查看刚才创建的数据库中存在什么表:mysql>show tables;(说明刚才创建的数据库中还没有数据库表)接着我们创建一个关于 students 的数据表:包括学生的学号(id),姓名(name),性别(sex),年龄(age)
mysql>create table students(id int unsigned not null auto_increment primary key,name char(8) not null,sex char(4) not null,age tinyint unsigned not null,);解释:以 ”id int unsigned not null auto_increment primary key” 行进行介绍:”id” 为列的名称;"int” 指定该列的类型为 int(取值范围为 —8388608 到 8388607), 在后面我们又用 "unsigned” 加以修饰, 表示该类型为无符号型, 此时该列的取值范围为 0 到 16777215;”not null” 说明该列的值不能为空, 必须要填, 假如不指定该属性, 默认可为空;”auto_increment" 需在整数列中使用, 其作用是在插入数据时若该列为 NULL, MySQL 将自动产生一个比现存值更大的唯一标识符值
在每张表中仅能有一个这样的值且所在列必须为索引列
"primary key" 表示该列是表的主键, 本列的值必须唯一, MySQL 将自动索引该