網(wǎng)站建設在線視頻百度云搜索入口
目錄
一、創(chuàng)建數(shù)據(jù)庫
1,創(chuàng)建數(shù)據(jù)庫規(guī)則
2、創(chuàng)建案例
二、字符集和校驗規(guī)則
1、查看系統(tǒng)默認字符集以及校驗規(guī)則
2、查看數(shù)據(jù)庫支持的字符集以及校驗規(guī)則
3、校驗規(guī)則對數(shù)據(jù)庫的影響
三、操縱數(shù)據(jù)庫
1、查看數(shù)據(jù)庫和目前所在數(shù)據(jù)庫
2、顯示創(chuàng)建語句
3、修改數(shù)據(jù)庫
4、刪除數(shù)據(jù)庫
5、備份和恢復
6、查看連接情況
一、創(chuàng)建數(shù)據(jù)庫
1,創(chuàng)建數(shù)據(jù)庫規(guī)則
語法:
CREATE DATABASE [IF NOT EXISTS] db_name [create_specification [,
create_specification] ...]create_specification:[DEFAULT] CHARACTER SET charset_name[DEFAULT] COLLATE collation_name
2、創(chuàng)建案例
create database db1;
create database db2 charset=utf8;
create database db3 charset=utf8 collate utf8_general_ci;
二、字符集和校驗規(guī)則
數(shù)據(jù)庫的字符集是指數(shù)據(jù)庫中存儲的字符所使用的編碼方式,不同的字符集可以表示不同的字符范圍和大小。數(shù)據(jù)庫的檢驗規(guī)則是指數(shù)據(jù)庫中比較和排序字符時所遵循的規(guī)則,不同的檢驗規(guī)則會影響到查詢結(jié)果和性能。
1、查看系統(tǒng)默認字符集以及校驗規(guī)則
show variables like 'character_set_database';
show variables like 'collation_database';
2、查看數(shù)據(jù)庫支持的字符集以及校驗規(guī)則
show charset;
\
show collation;
3、校驗規(guī)則對數(shù)據(jù)庫的影響
create database option1 collate utf8_general_ci;
use option1;
create table person(name varchar(20));
insert into person values('a');
insert into person values('A');
insert into person values('b');
insert into person values('B');

create database option2 collate utf8_bin;
use option2;
create table person(name varchar(20));
insert into person values('a');
insert into person values('A');
insert into person values('b');
insert into person values('B');
(3)對倆個數(shù)據(jù)庫里面的表進行查找和排序
數(shù)據(jù)庫option1校驗規(guī)則使用utf8_ general_ ci[不區(qū)分大小寫]
use option1;
mysql> select * from person where name='a';
select * from person order by name;
數(shù)據(jù)庫option2校驗規(guī)則使用utf8_ general_ ci[區(qū)分大小寫]
use option2;
mysql> select * from person where name='a';
select * from person order by name;
三、操縱數(shù)據(jù)庫
1、查看數(shù)據(jù)庫和目前所在數(shù)據(jù)庫
show databases;
select database();
2、顯示創(chuàng)建語句
show create database option1;
3、修改數(shù)據(jù)庫
對數(shù)據(jù)庫的修改主要指的是修改數(shù)據(jù)庫的字符集,校驗規(guī)則
ALTER DATABASE db_name
[alter_spacification [,alter_spacification]...]
alter_spacification:
[DEFAULT] CHARACTER SET charset_name
[DEFAULT] COLLATE collation_name
alter database option1 charset=gbk;
上面的代碼將 option1數(shù)據(jù)庫字符集改成 gbk。
4、刪除數(shù)據(jù)庫
drop database option2;
5、備份和恢復
(1)備份
mysqldump -P3306 -u root -p 密碼 -B 數(shù)據(jù)庫名 > 數(shù)據(jù)庫備份存儲的文件路徑
示例:將option1庫備份到文件(退出連接)
mysqldump -P3306 -uroot -p -B option1 >test1.sql
可以看到備份后,該路徑下有了test.sql文件,接下來用vim打開看一下內(nèi)容
2(恢復數(shù)據(jù)庫)
source /var/lib/mysql/test1.sql;
(3)注意事項
mysqldump -u root -p 數(shù)據(jù)庫名 表名1 表名2 > D:/mytest.sql
# mysqldump -u root -p -B 數(shù)據(jù)庫名1 數(shù)據(jù)庫名2 ... > 數(shù)據(jù)庫存放路徑
6、查看連接情況
show processlist;
?