備份數(shù)據(jù)庫(kù)
shell> mysqldump -h host -u root -p dbname >dbname_backup.sql
恢復(fù)數(shù)據(jù)庫(kù)
shell> mysqladmin -h myhost -u root -p create dbname
shell> mysqldump -h host -u root -p dbname < dbname_backup.sql
如果只想卸出建表指令,則命令如下:
shell> mysqladmin -u root -p -d databasename > a.sql
如果只想卸出插入數(shù)據(jù)的sql命令,而不需要建表命令,則命令如下:
shell> mysqladmin -u root -p -t databasename > a.sql
那么如果我只想要數(shù)據(jù),而不想要什么sql命令時(shí),應(yīng)該如何操作呢?
mysqldump -T./ phptest driver
其中,只有指定了-T參數(shù)才可以卸出純文本文件,表示卸出數(shù)據(jù)的目錄,./表示當(dāng)前目錄,即與mysqldump同一目錄。如果不指定driver 表,則將卸出整個(gè)數(shù)據(jù)庫(kù)的數(shù)據(jù)。每個(gè)表會(huì)生成兩個(gè)文件,一個(gè)為.sql文件,包含建表執(zhí)行。另一個(gè)為.txt文件,只包含數(shù)據(jù),且沒(méi)有sql指令。
5、可將查詢(xún)存儲(chǔ)在一個(gè)文件中并告訴mysql從文件中讀取查詢(xún)而不是等待鍵盤(pán)輸入?衫猛鈿こ绦蜴I入重定向?qū)嵱贸绦騺?lái)完成這項(xiàng)工作。例如,如果在文件my_file.sql 中存放有查
詢(xún),可如下執(zhí)行這些查詢(xún):
例如,如果您想將建表語(yǔ)句提前寫(xiě)在sql.txt中:
mysql > mysql -h myhost -u root -p database < sql.txt
1、安裝環(huán)境:
Windows XP
Mysql 4.0.17 從 下次就需要用mysql -uroot -proot才可以登陸
在遠(yuǎn)程或本機(jī)可以使用 mysql -h 172.5.1.183 -uroot 登陸,這個(gè)根據(jù)第二行的策略確定
權(quán)限修改生效:
1)net stop mysql
net start mysql
2)c:\mysql\bin\mysqladmin flush-privileges
3)登陸mysql后,用flush privileges語(yǔ)句
6、創(chuàng)建數(shù)據(jù)庫(kù)staffer
create database staffer;
7、下面的語(yǔ)句在mysql環(huán)境在執(zhí)行
顯示用戶擁有權(quán)限的數(shù)據(jù)庫(kù) show databases;
切換到staffer數(shù)據(jù)庫(kù) use staffer;
顯示當(dāng)前數(shù)據(jù)庫(kù)中有權(quán)限的表 show tables;
顯示表staffer的結(jié)構(gòu) desc staffer;
8、創(chuàng)建測(cè)試環(huán)境
1)創(chuàng)建數(shù)據(jù)庫(kù)staffer
mysql> create database staffer
2)創(chuàng)建表staffer,department,position,depart_pos
create table s_position
(
id int not null auto_increment,
name varchar(20) not null default '經(jīng)理', #設(shè)定默認(rèn)值
description varchar(100),
primary key PK_positon (id) #設(shè)定主鍵
);
create table department
(
id int not null auto_increment,
name varchar(20) not null default '系統(tǒng)部', #設(shè)定默認(rèn)值
description varchar(100),
primary key PK_department (id) #設(shè)定主鍵
);
create table depart_pos
(
department_id int not null,
position_id int not null,
primary key PK_depart_pos (department_id,position_id) #設(shè)定復(fù)和主鍵
);
create table staffer
(
id int not null auto_increment primary key, #設(shè)定主鍵
name varchar(20) not null default '無(wú)名氏', #設(shè)定默認(rèn)值
department_id int not null,
position_id int not null,
unique (department_id,position_id) #設(shè)定唯一值
);
3)刪除
mysql>
drop table depart_pos;
drop table department;
drop table s_position;
drop table staffer;
drop database staffer;
9、修改結(jié)構(gòu)
mysql>
#表position增加列test
alter table position add(test char(10));
#表position修改列test
alter table position modify test char(20) not null;
#表position修改列test默認(rèn)值
alter table position alter test set default 'system';
#表position去掉test默認(rèn)值
alter table position alter test drop default;
#表position去掉列test
alter table position drop column test;
#表depart_pos刪除主鍵
alter table depart_pos drop primary key;
#表depart_pos增加主鍵
alter table depart_pos add primary key PK_depart_pos (department_id,position_id);
本文導(dǎo)航
- 第1頁(yè): 首頁(yè)
- 第2頁(yè): 修改mYSQL 管理員密碼
- 第3頁(yè): 增加新用
- 第4頁(yè): 恢復(fù)、備份數(shù)據(jù)庫(kù)
- 第5頁(yè): 操作數(shù)據(jù)