存儲引擎
1)innodb
支持?jǐn)?shù)據(jù)庫高級功能:事務(wù)(要么整體成功要么整體失敗)外鍵
2)myisam
1.不支持事務(wù)页屠,外鍵粹胯,只有數(shù)據(jù)存儲基本功能
2.效率非常高
刪除數(shù)據(jù)庫
drop database if exists db1;
創(chuàng)建表
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;
-- 設(shè)置字段為空
alter table tb1 modify num int null;
-- 設(shè)置自增
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;
-- 查看安裝數(shù)據(jù)庫后的編碼
show variables like 'char%';
-- 運行結(jié)果
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)
-- 查看特定數(shù)據(jù)庫的編碼
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)