一、備份與還原
/***************************樣例表***************************/
CREATE DATABASE booksDB;
use booksDB;
CREATE TABLE books
(
bk_id INT NOT NULL PRIMARY KEY,
bk_title VARCHAR(50) NOT NULL,
copyright YEAR NOT NULL
);
INSERT INTO books
VALUES (11078, 'Learning MySQL', 2010),
(11033, 'Study Html', 2011),
(11035, 'How to use php', 2003),
(11072, 'Teach youself javascript', 2005),
(11028, 'Learing C++', 2005),
(11069, 'MySQL professional', 2009),
(11026, 'Guide to MySQL 5.5', 2008),
(11041, 'Inside VC++', 2011);
CREATE TABLE authors
(
auth_id INT NOT NULL PRIMARY KEY,
auth_name VARCHAR(20),
auth_gender CHAR(1)
);
INSERT INTO authors
VALUES (1001, 'WriterX' ,'f'),
(1002, 'WriterA' ,'f'),
(1003, 'WriterB' ,'m'),
(1004, 'WriterC' ,'f'),
(1011, 'WriterD' ,'f'),
(1012, 'WriterE' ,'m'),
(1013, 'WriterF' ,'m'),
(1014, 'WriterG' ,'f'),
(1015, 'WriterH' ,'f');
CREATE TABLE authorbook
(
auth_id INT NOT NULL,
bk_id INT NOT NULL,
PRIMARY KEY (auth_id, bk_id),
FOREIGN KEY (auth_id) REFERENCES authors (auth_id),
FOREIGN KEY (bk_id) REFERENCES books (bk_id)
);
INSERT INTO authorbook
VALUES (1001, 11033), (1002, 11035), (1003, 11072), (1004, 11028),
(1011, 11078), (1012, 11026), (1012, 11041), (1014, 11069);
1、使用mysqldump命令備份數(shù)據(jù)庫中的所有表
2、備份booksDB數(shù)據(jù)庫中的books表
3、使用mysqldump備份booksDB和test數(shù)據(jù)庫
4、使用mysqldump備份服務(wù)器中的所有數(shù)據(jù)庫
5、使用mysql命令還原第二題導(dǎo)出的book表
6、進(jìn)入數(shù)據(jù)庫使用source命令還原第二題導(dǎo)出的book表
索引
1、建立一個(gè)utf8編碼的數(shù)據(jù)庫test1
2、建立商品表goods和欄目表category
按如下表結(jié)構(gòu)創(chuàng)建表:存儲(chǔ)引擎engine myisam 字符集charset utf8
mysql> desc goods;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| goods_id | int(11) | NO | PRI | NULL | auto_increment |
| goods_name | varchar(20) | NO | | | |
| cat_id | int(11) | NO | | 0 | |
| brand_id | int(11) | NO | | 0 | |
| goods_sn | char(12) | NO | | | |
| shop_price | float(6,2) | NO | | 0.00 | |
| goods_desc | text | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> desc category;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| cat_id | int(11) | NO | PRI | NULL | auto_increment |
| cate_name | varchar(20) | NO | | | |
| parent_id | int(11) | NO | | 0 | |
+-----------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
3、刪除 goods 表中的 goods_desc 字段及貨號(hào)字段,并增加 click_count 字段
4、在 goods_name 列上加唯一性索引(用alter table方式)
5、在 shop_price 列上加普通索引(用create index方式)
6、在 click_count 上增加普通索引,然后再刪除 (分別使用drop index和alter table刪除)
2、建立商品表goods和欄目表category
create table goods(
-> googs_id int(11) primary key auto_increment,
-> goods_name varchar(20) not null,
-> cat_id int(11) not null default 0,
-> brand_id int(11) not null default 0,
-> goods_sn char(12) not null,
-> shop_price float(6,2) not null default 0.00,
-> goods_desc text default NULL
-> );
create table category(
-> cat_id int(11) primary key auto_increment,
-> cate_name varchar(20) not null,
-> parent_id int(11) not null default 0);
3、刪除 goods 表中的 goods_desc 字段及貨號(hào)字段,并增加 click_count 字段
ps:本人創(chuàng)表時(shí)字段名寫錯(cuò)了(good_id寫成了goog_id)
4、在 goods_name 列上加唯一性索引(用alter table方式)
5、在 shop_price 列上加普通索引(用create index方式)文章來源:http://www.zghlxwxcb.cn/news/detail-554702.html
6、在 click_count 上增加普通索引,然后再刪除 (分別使用drop index和alter table刪除)
視圖
學(xué)生表:Student (Sno, Sname, Ssex , Sage, Sdept)
學(xué)號(hào),姓名,性別,年齡,所在系 Sno為主鍵
課程表:Course (Cno, Cname,)
課程號(hào),課程名 Cno為主鍵
學(xué)生選課表:SC (Sno, Cno, Score)
學(xué)號(hào),課程號(hào),成績 Sno,Cno為主鍵
1、創(chuàng)建一視圖 stu_info,查詢?nèi)w學(xué)生的姓名,性別,課程名,成績。
2、刪除視圖 stu_info。文章來源地址http://www.zghlxwxcb.cn/news/detail-554702.html
到了這里,關(guān)于數(shù)據(jù)備份與還原,(mysqldump,source)索引(index),創(chuàng)建視圖(view)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!