備份數(shù)據(jù)庫
shell> mysqldump -h host -u root -p dbname >dbname_backup.sql
恢復(fù)數(shù)據(jù)庫
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命令時,應(yīng)該如何操作呢?
mysqldump -T./ phptest driver
其中,只有指定了-T參數(shù)才可以卸出純文本文件,表示卸出數(shù)據(jù)的目錄,./表示當(dāng)前目錄,即與mysqldump同一目錄。如果不指定driver 表,則將卸出整個數(shù)據(jù)庫的數(shù)據(jù)。每個表會生成兩個文件,一個為.sql文件,包含建表執(zhí)行。另一個為.txt文件,只包含數(shù)據(jù),且沒有sql指令。
5、可將查詢存儲在一個文件中并告訴mysql從文件中讀取查詢而不是等待鍵盤輸入?衫猛鈿こ绦蜴I入重定向?qū)嵱贸绦騺硗瓿蛇@項工作。例如,如果在文件my_file.sql 中存放有查
詢,可如下執(zhí)行這些查詢:
例如,如果您想將建表語句提前寫在sql.txt中:
mysql > mysql -h myhost -u root -p database < sql.txt
1、安裝環(huán)境:
Windows XP
Mysql 4.0.17 從 下次就需要用mysql -uroot -proot才可以登陸
在遠程或本機可以使用 mysql -h 172.5.1.183 -uroot 登陸,這個根據(jù)第二行的策略確定
權(quán)限修改生效:
1)net stop mysql
net start mysql
2)c:\mysql\bin\mysqladmin flush-privileges
3)登陸mysql后,用flush privileges語句
6、創(chuàng)建數(shù)據(jù)庫staffer
create database staffer;
7、下面的語句在mysql環(huán)境在執(zhí)行
顯示用戶擁有權(quán)限的數(shù)據(jù)庫 show databases;
切換到staffer數(shù)據(jù)庫 use staffer;
顯示當(dāng)前數(shù)據(jù)庫中有權(quán)限的表 show tables;
顯示表staffer的結(jié)構(gòu) desc staffer;
8、創(chuàng)建測試環(huán)境
1)創(chuàng)建數(shù)據(jù)庫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è)定默認值
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è)定默認值
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 '無名氏', #設(shè)定默認值
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默認值
alter table position alter test set default 'system';
#表position去掉test默認值
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頁: 首頁
- 第2頁: 修改mYSQL 管理員密碼
- 第3頁: 增加新用
- 第4頁: 恢復(fù)、備份數(shù)據(jù)庫
- 第5頁: 操作數(shù)據(jù)