商城網(wǎng)站建設(shè)招聘網(wǎng)站推廣方式有哪些
目錄
數(shù)據(jù)庫創(chuàng)建,刪除基礎(chǔ)指令:
數(shù)據(jù)庫的編碼集:
數(shù)據(jù)庫備份與恢復(fù):
表的操作:
數(shù)據(jù)庫創(chuàng)建,刪除基礎(chǔ)指令:
show databases;//查看數(shù)據(jù)庫列表
//創(chuàng)建數(shù)據(jù)庫
create database db_name;
create database if not exists db_name;//刪除數(shù)據(jù)庫
drop database db_name;
創(chuàng)建數(shù)據(jù)庫的本質(zhì)在數(shù)據(jù)庫安裝的路徑下創(chuàng)建目錄
而刪除數(shù)據(jù)庫的本質(zhì)其實就是刪除目錄。
數(shù)據(jù)庫的編碼集:
- 數(shù)據(jù)庫編碼集
- 數(shù)據(jù)庫未來存儲數(shù)據(jù)采用的編碼集
- 數(shù)據(jù)庫校驗集
//查看數(shù)據(jù)庫支持的所有字符集
show charset;
?指定編碼集創(chuàng)建數(shù)據(jù)庫:
//指定創(chuàng)建的數(shù)據(jù)庫的編碼集和校驗集
create database 數(shù)據(jù)庫名 charset=utf8 collate utf8_general_ci;
//查看表的編碼集和校驗集
cat d4/db.opt
//進入某個數(shù)據(jù)庫
use db_name;//進入后,在某個庫中建表,括號中為表的成員
create table if not exists(name varchar(20));
//看表
show tables;//插入
insert into person (name) values ('a');//查找
select * from person;//嚴格匹配查找
select * from person where name ='a';//排序
select * from person order by name;
?
?
//查看創(chuàng)建數(shù)據(jù)庫的命令
show create database db_name;
數(shù)據(jù)庫備份與恢復(fù):
備份的數(shù)據(jù)庫不僅備份了數(shù)據(jù)內(nèi)容,還把sql的命令也備份了
//備份
mysqldump -p3306 -u root -p 密碼 -B 數(shù)據(jù)庫名 > 數(shù)據(jù)庫備份存儲的文件路徑
//備份數(shù)據(jù)庫中的某一張表
mysqldump -u root -p 數(shù)據(jù)庫名 表名1 > 數(shù)據(jù)庫備份存儲的文件路徑
//還原
source 備份的文件
表的操作:
增加表
//創(chuàng)建表
create table table_name(建表字段,建表字段,...);
//查看表
desc 表名;
?
//顯示創(chuàng)建表的詳細信息
show create table 表名 \G
?
?修改表:
//修改表名
alter table 表名 rename to 表名
//插入信息
insert into 表名 values(插入信息);
//添加表屬性
alter table 表名 add 新添加屬性 after 需要插入到哪一列后面
//修改表的某一列 修改的列名的屬性也需要重新設(shè)置alter table 表名 modify 要修改的列名 修改的屬性;
//刪除某一列
alter table 表名 drop 需要刪除的列名
//刪除表
drop table 表名;
?
?
刪除某一列,被刪除的列數(shù)據(jù)會全部丟失。?
?
?