存储引擎
1)innodb
支持数据库高级功能:事务(要么整体成功要么整体失败)外键
2)myisam
1.不支持事务,外键,只有数据存储基本功能
2.效率非常高
删除数据库
drop database if exists db1;
创建表
create table tb1(
id int primary key auto_increment,
name varchar(20) not null,
num int not null unique,
xid int,
foreign key(xid) references tb2(id)
)engine=innodb charset=utf8;
更改表
-- 增加gender列
alter table tb1 add gender char(1) after name;
-- 设置字段为空
alter table tb1 modify num int null;
-- 设置自增
alter table tb1 modify id int auto_increment;
-- 去掉自增
alter table tb1 modify id int;
-- 删除主键
alter table tb1 drop primary key;
-- 删除外键
alter table tb1 drop foreign key (外键约束);
-- 删除约束
alter table tb1 drop index 约束名;
-- 删除表
drop table if exists tb1;
-- 查看安装数据库后的编码
show variables like 'char%';
-- 运行结果
root@localhost:(none)>show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.5\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
-- 查看特定数据库的编码
show create database test;
root@localhost:test>show create database test;
+----------+---------------------------------------------------------------+
| Database | Create Database |
+----------+---------------------------------------------------------------+
| test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+---------------------------------------------------------------+
1 row in set (0.00 sec)