用 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 将自动索引该列.下面的 char(8) 表示存储的字符长度为 8, tinyint 的取值范围为 —127 到 128, default 属性指定当该列值为空时的默认值.创建一个表后,用 show tables 显示数据库中有哪些表:mysql〉show tables;5、显示表结构:mysql〉describe students;6、在表中添加记录:首先用 select 命令来查看表中的数据:mysql>select*from students;(说明刚才创建的数据库表中还没有任何记录)接着加入一条新纪录:mysql〉insert into students value(‘01’,’Tom’,’F’,'18');再用 select 命令来查看表中的数据的变化:mysql〉select*from students;7、用文本方式将数据装入一个数据库表:创建一个文本文件“student。sql",每行包括一个记录,用 TAB 键把值分开,并且以在 create table 语句中列出的次序,例如:02 TonyF1803 AmyM 1804 LisaM 18将文本文件“student.sql”装载到 students 表中:mysql>load data local infile”e:\\student.sql”into table students;再使用 select 命令来查看表中的数据的变化:mysql〉select*from students;