《學習》14資料庫備份修復

2022-07-15 01:27:11 字數 1474 閱讀 8396

create database db

use db;

create table stu

(id int unsigned not null auto_increment,

sname varchar(20),

sage tinyint unsigned,

key(sname),

primary key(id)

)engine=myisam default charset=utf8;

insert into stu values(null,'張三',20),(null,'李四',30);

select * from stu;

truncate table stu;

delete from stu;

-- 匯出db資料庫 大於號

mysqldump -uroot db>d:/db.sql

-- 匯入db資料庫 小於號 可以匯出到任何資料庫而且重新建個同名表

mysql -uroot -q db-- 在cmd命令視窗進行 恢復資料之前一定要選擇資料庫

-- 只匯出表的資料

mysqldump -t -q -uroot db>d:/db.sql

-- 匯出表的結構

mysqldump -d -q uroot db>d:/db.sql

-- 匯出表stu的資料 也可以同時匯出多個表

mysqldump -t -q uroot db stu xx xx>d:/db.sql

-- 恢復資料

source d:/db.sql;

drop database db;

-- 按格式把資料寫入**

load data infile 'd:/aa.txt' into table stu fields terminated by '\,' lines terminated by '\r\n';

alter database db charset utf8;

-- 將查詢的結果匯出到dd.txt檔案,乙個記錄佔一行 換行符\r\n 字段之間用','隔開(\,)

select sname,sage into outfile 'd:/dd.txt' fields terminated by '\,' lines terminated by '\r\n' from stu where sage<18;

-- 將查詢的結果匯出到dd.xls檔案(亂碼)

select sname,sage into outfile 'd:/dd.xls' fields terminated by '\,' lines terminated by '\r\n' from stu;

-------------------------------------

優化表與修復表

-- 修復表

repair table stu,text.tb3;

-- 優化表

optimize table stu;

《學習》14資料庫備份修復

create database db use db create table stu id int unsigned not null auto increment,sname varchar 20 sage tinyint unsigned,key sname primary key id eng...

資料庫備份修復 如何通過備份修復表資料庫

資料庫備份修復 how to repair tables database by backup 如何通過備份 修復表資料庫 is this possible?這可能嗎?please explain how to repair.請說明如何修理。and thanks 謝謝 this post may h...

資料庫修復

sql2008資料庫 檢測資料庫 dbcc checkdb 單使用者和多使用者模式切換 alter database dbname資料庫 set single user 單使用者 alter database dbname資料庫 set multi user 多使用者 修復dbcc checktab...