cmd链接数据库:
mysql -h主机名 -u用户名 -p密码;
数据库命令:
1.创建数据库
create database 数据库名;
示例:
create database itsourse;
数据库名不建议写成关键字,如果一定要写成关键字,那么必须加反引号``;
数据库名、表名、字段名都不建议写成大写,一般严格区分大小写(windows不区分,linux等区分);
2.查看数据库列表
show databases;
3.删除数据库
drop database 数据库名;
数据表命令:
1.创建数据表
create table 数据表名(
字段名 字段类型 字段长度 属性修饰,
字段名2 字段类型2 字段长度2 属性修饰2
);
示例:创建一个学生表
create table student (
id int primary key auto_increment,
name varchar(30),
age int,
gender varchar(10)
);
2.查看数据表
show tables;//查看当前数据库中的所有数据表
desc 数据表名;//查看当前数据表结构
其中,field为字段,type为类型,null为允不允许这个数据为空(如果name不允许为空,则写为name varchar(30) not null),key为键,default为默认值,extra为扩展。
show create table 数据表名;//查看数据表的建表语句
关于数据库文件夹中的内容:
数据库文件夹中有四个文件,其中db.opt文件为数据库配置文件;.frm文件为数据表结构存储文件;.myd文件为数据表存储的文件;myi为索引文件。
insert into student(name,age,gender)values(‘张三’,18,‘男’);
待续。。。。