日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

mysql库可以无限创建吗_mysql 创建库

發(fā)布時間:2023/11/27 生活经验 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql库可以无限创建吗_mysql 创建库 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

常用的MySQL命令大全

一、連接MySQL

格式: mysql -h主機地址 -u用戶名 -p用戶密碼

1、例1:連接到本機上的MYSQL。

首先在打開DOS窗口,然后進入目錄 mysqlbin,再鍵入命令mysql -uroot -p,回車后提示你輸密碼,如果剛安裝好MYSQL,超級用戶root是沒有密碼的,故直接回車即可進入到MYSQL中了,MYSQL的提示符是: mysql>。

2、例2:連接到遠程主機上的MYSQL。假設(shè)遠程主機的IP為:110.110.110.110,用戶名為root,密碼為abcd123。則鍵入以下命令:

mysql -h110.110.110.110 -uroot -pabcd123

(注:u與root可以不用加空格,其它也一樣)

3、退出MYSQL命令: exit (回車)。

二、修改密碼

格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼

1、例1:給root加個密碼ab12。首先在DOS下進入目錄mysqlbin,然后鍵入以下命令:

mysqladmin -uroot -password ab12

注:因為開始時root沒有密碼,所以-p舊密碼一項就可以省略了。

2、例2:再將root的密碼改為djg345。

mysqladmin -uroot -pab12 password djg345

三、增加新用戶。(注意:和上面不同,下面的因為是MySQL環(huán)境中的命令,所以后面都帶一個分號作為命令結(jié)束符)

格式:grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by \"密碼\"

例1、增加一個用戶test1密碼為abc,讓他可以在任何主機上登錄,并對所有數(shù)據(jù)庫有查詢、插入、修改、刪除的權(quán)限。首先用以root用戶連入MySQL,然后鍵入以下命令:

grant select,insert,update,

delete on *.* to test2@localhost identified by \"abc\";

如果你不想test2有密碼,可以再打一個命令將密碼消掉。

grant select,insert,update,delete on mydb

.* to test2@localhost identified by \"\";

在上面講了登錄、增加用戶、密碼更改等問題。下面我們來看看MySQL中有關(guān)數(shù)據(jù)庫方面的操作。注意:你必須首先登錄到MySQL中,以下操作都是在MySQL的提示符下進行的,而且每個命令以分號結(jié)束。

1、MySQL常用命令

create database name; 創(chuàng)建數(shù)據(jù)庫

use databasename; 選擇數(shù)據(jù)庫

drop database name 直接刪除數(shù)據(jù)庫,不提醒

show tables; 顯示表

describe tablename; 表的詳細描述

select 中加上distinct去除重復(fù)字段

mysqladmin drop database name 刪除數(shù)據(jù)庫前,有提示。

顯示當(dāng)前mysql版本和當(dāng)前日期

select version(),current_date;

2、修改mysql中root的密碼:

shell>mysql -u root -p

mysql> update user set password=password(”xueok654123″) where user=’root’;

mysql> flush privileges //刷新數(shù)據(jù)庫

mysql>use dbname; 打開數(shù)據(jù)庫:

mysql>show databases; 顯示所有數(shù)據(jù)庫

mysql>show tables; 顯示數(shù)據(jù)庫mysql中所有的表:先use mysql;然后

mysql>describe user; 顯示表mysql數(shù)據(jù)庫中user表的列信息);

3、grant

創(chuàng)建一個可以從任何地方連接服務(wù)器的一個完全的超級用戶,但是必須使用一個口令something做這個

mysql> grant all privileges on *.* to user@localhost identified by ’something’ with

增加新用戶

格式:grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by “密碼”

GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY ’something’ WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO monty@”%” IDENTIFIED BY ’something’ WITH GRANT OPTION;

刪除授權(quán):

mysql> revoke all privileges on *.* from root@”%”;

mysql> delete from user where user=”root” and host=”%”;

mysql> flush privileges;

創(chuàng)建一個用戶custom在特定客戶端it363.com登錄,可訪問特定數(shù)據(jù)庫fangchandb

mysql >grant select, insert, update, delete, create,drop on fangchandb.* to custom@ it363.com identified by ‘ passwd’

重命名表:

mysql > alter table t1 rename t2;

4、mysqldump

備份數(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從文件中讀取查詢而不是等待鍵盤輸入。可利用外殼程序鍵入重定向?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);

10、操作數(shù)據(jù)

#插入表department

insert into department(name,description) values('系統(tǒng)部','系統(tǒng)部');

insert into department(name,description) values('公關(guān)部','公關(guān)部');

insert into department(name,description) values('客服部','客服部');

insert into department(name,description) values('財務(wù)部','財務(wù)部');

insert into department(name,description) values('測試部','測試部');

#插入表s_position

insert into s_position(name,description) values('總監(jiān)','總監(jiān)');

insert into s_position(name,description) values('經(jīng)理','經(jīng)理');

insert into s_position(name,description) values('普通員工','普通員工');

#插入表depart_pos

insert into depart_pos(department_id,position_id)

select a.id department_id,b.id postion_id

from department a,s_position b;

#插入表staffer

insert into staffer(name,department_id,position_id) values('陳達治',1,1);

insert into staffer(name,department_id,position_id) values('李文賓',1,2);

insert into staffer(name,department_id,position_id) values('馬佳',1,3);

insert into staffer(name,department_id,position_id) values('亢志強',5,1);

insert into staffer(name,department_id,position_id) values('楊玉茹',4,1);

11、查詢及刪除操作

#顯示系統(tǒng)部的人員和職位

select a.name,b.name department_name,c.name position_name

from staffer a,department b,s_position c

where a.department_id=b.id and a.position_id=c.id and b.name='系統(tǒng)部';

#顯示系統(tǒng)部的人數(shù)

select count(*) from staffer a,department b

where a.department_id=b.id and b.name='系統(tǒng)部'

#顯示各部門的人數(shù)

select count(*) cou,b.name

from staffer a,department b

where a.department_id=b.id

group by b.name;

#刪除客服部

delete from department where name='客服部';

#將財務(wù)部修改為財務(wù)一部

update department set name='財務(wù)一部' where name='財務(wù)部';

12、備份和恢復(fù)

備份數(shù)據(jù)庫staffer

c:\mysql\bin\mysqldump -uroot -proot staffer>e:\staffer.sql

得到的staffer.sql是一個sql腳本,不包括建庫的語句,所以你需要手工

創(chuàng)建數(shù)據(jù)庫才可以導(dǎo)入

恢復(fù)數(shù)據(jù)庫staffer,需要創(chuàng)建一個空庫staffer

c:\mysql\bin\mysql -uroot -proot staffer

如果不希望后來手工創(chuàng)建staffer,可以

c:\mysql\bin\mysqldump -uroot -proot --databases staffer>e:\staffer.sql

mysql -uroot -proot >e:\staffer.sql

但這樣的話系統(tǒng)種就不能存在staffer庫,且無法導(dǎo)入其他名字的數(shù)據(jù)庫,

當(dāng)然你可以手工修改staffer.sql文件

13、從文本向數(shù)據(jù)庫導(dǎo)入數(shù)據(jù)

1)使用工具c:\mysql\bin\mysqlimport

這個工具的作用是將文件導(dǎo)入到和去掉文件擴展名名字相同的表里,如

staffer.txt,staffer都是導(dǎo)入到staffer表中

常用選項及功能如下

-d or --delete 新數(shù)據(jù)導(dǎo)入數(shù)據(jù)表中之前刪除數(shù)據(jù)數(shù)據(jù)表中的所有信息

-f or --force 不管是否遇到錯誤,mysqlimport將強制繼續(xù)插入數(shù)據(jù)

-i or --ignore mysqlimport跳過或者忽略那些有相同唯一

關(guān)鍵字的行, 導(dǎo)入文件中的數(shù)據(jù)將被忽略。

-l or -lock-tables 數(shù)據(jù)被插入之前鎖住表,這樣就防止了,

你在更新數(shù)據(jù)庫時,用戶的查詢和更新受到影響。

-r or -replace 這個選項與-i選項的作用相反;此選項將替代

表中有相同唯一關(guān)鍵字的記錄。

--fields-enclosed- by= char

指定文本文件中數(shù)據(jù)的記錄時以什么括起的, 很多情況下

數(shù)據(jù)以雙引號括起。 默認的情況下數(shù)據(jù)是沒有被字符括起的。

--fields-terminated- by=char

指定各個數(shù)據(jù)的值之間的分隔符,在句號分隔的文件中,

分隔符是句號。您可以用此選項指定數(shù)據(jù)之間的分隔符。

默認的分隔符是跳格符(Tab)

--lines-terminated- by=str

此選項指定文本文件中行與行之間數(shù)據(jù)的分隔字符串

或者字符。 默認的情況下mysqlimport以newline為行分隔符。

您可以選擇用一個字符串來替代一個單個的字符:

一個新行或者一個回車。

mysqlimport命令常用的選項還有-v 顯示版本(version),

-p 提示輸入密碼(password)等。

這個工具有個問題,無法忽略某些列,這樣對我們的數(shù)據(jù)導(dǎo)入有很大的麻煩,雖然可以手工設(shè)置這個字段,但會出現(xiàn)莫名其妙的結(jié)果,我們做一個簡單的示例

我們定義如下的depart_no.txt,保存在e盤,間隔為制表符\t

10 10

11 11

12 24

執(zhí)行如下命令

c:\mysql\bin\mysqlimport -uroot -proot staffer e:\depart_pos.txt

在這里沒有使用列的包圍符號,分割采用默認的\t,因為采用別的符號會有問題,

不知道是不是windows的原因

2)Load Data INFILE file_name into table_name(column1_name,column2_name)

這個命令在mysql>提示符下使用,優(yōu)點是可以指定列導(dǎo)入,示例如下

c:\mysql\bin\mysql -uroot -proot staffer

mysql>load data infile "e:/depart_no.txt" into depart_no(department_id,position_id);

這兩個工具在Windows下使用都有問題,不知道是Windows的原因還是中文的問題,

而且不指定的列它產(chǎn)生了空值,這顯然不是我們想要的,所以謹慎使用這些工具

進入MySQL:mysql -uuser -ppassword --port=3307

1:使用SHOW語句找出在服務(wù)器上當(dāng)前存在什么數(shù)據(jù)庫:

mysql> SHOW DATABASES;

2:2、創(chuàng)建一個數(shù)據(jù)庫MYSQLDATA

mysql> Create DATABASE MYSQLDATA;

3:選擇你所創(chuàng)建的數(shù)據(jù)庫

mysql> USE MYSQLDATA; (按回車鍵出現(xiàn)Database changed 時說明操作成功!)

4:查看現(xiàn)在的數(shù)據(jù)庫中存在什么表

mysql> SHOW TABLES;

5:創(chuàng)建一個數(shù)據(jù)庫表

mysql> Create TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));

6:顯示表的結(jié)構(gòu):

mysql> DESCRIBE MYTABLE;

7:往表中加入記錄

mysql> insert into MYTABLE values ("hyq","M");

8:用文本方式將數(shù)據(jù)裝入數(shù)據(jù)庫表中(例如D:/mysql.txt)

mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;

9:導(dǎo)入.sql文件命令(例如D:/mysql.sql)

mysql>use database;

mysql>source d:/mysql.sql;

10:刪除表

mysql>drop TABLE MYTABLE;

11:清空表

mysql>delete from MYTABLE;

12:更新表中數(shù)據(jù)

mysql>update MYTABLE set sex="f" where name='hyq';

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name

SET col_name1=expr1 [, col_name2=expr2 ...]

[WHERE where_definition]

[ORDER BY ...]

[LIMIT rows]

or

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name [, tbl_name ...]

SET col_name1=expr1 [, col_name2=expr2 ...]

[WHERE where_definition]

UPDATE 以新的值更新現(xiàn)存表中行的列。SET 子句指出要修改哪個列和他們應(yīng)該給定的值。WHERE

子句如果被給出,指定哪個記錄行應(yīng)該被更新。否則,所有的記錄行被更新。如果 ORDER BY 子句被指定,記錄行將被以指定的次序更新。

如果你指定關(guān)鍵詞 LOW_PRIORITY,UPDATE 的執(zhí)行將被延遲,直到?jīng)]有其它的客戶端正在讀取表。

如果你指定關(guān)鍵詞 IGNORE,該更新語句將不會異常中止,即使在更新過程中出現(xiàn)重復(fù)鍵錯誤。導(dǎo)致沖突的記錄行將不會被更新。

如果在一個表達式中從 tbl_name 中訪問一個列,UPDATE 使用列的當(dāng)前值。舉例來說,下面的語句設(shè)置 age 列值為它的當(dāng)前值加 1 :

mysql> UPDATE persondata SET age=age+1;

UPDATE 賦值是從左到右計算的。舉例來說,下列語句將 age 列設(shè)置為它的兩倍,然后再加 1 :

mysql> UPDATE persondata SET age=age*2, age=age+1;

如果你設(shè)置列為其當(dāng)前的值,MySQL 注意到這點,并不更新它。

UPDATE 返回實際被改變的記錄行數(shù)目。在 MySQL 3.22 或更新的版本中,C API 函數(shù) mysql_info()

返回被匹配并更新的記錄行數(shù)目,以及在 UPDATE 期間發(fā)生的警告的數(shù)目。

在 MySQL 3.23 中,你可以使用 LIMIT # 來確保只有給定的記錄行數(shù)目被更改。

如果一個 ORDER BY 子句被使用(從 MySQL 4.0.0 開始支持),記錄行將以指定的次序被更新。這實際上只有連同 LIMIT一起才有用。

從 MySQL 4.0.4 開始,你也可以執(zhí)行一個包含多個表的 UPDATE 的操作:

UPDATE items,month SET items.price=month.price

WHERE items.id=month.id;

注意:多表 UPDATE 不可以使用 ORDER BY 或 LIMIT。

關(guān)鍵字: mysql

啟動:net start mySql;

進入:mysql -u root -p/mysql -h localhost -u root -p databaseName;

列出數(shù)據(jù)庫:show databases;

選擇數(shù)據(jù)庫:use databaseName;

列出表格:show tables;

顯示表格列的屬性:show columns from tableName;

建立數(shù)據(jù)庫:source fileName.txt;

匹配字符:可以用通配符_代表任何一個字符,%代表任何字符串;

增加一個字段:alter table tabelName add column fieldName dateType;

增加多個字段:alter table tabelName add column fieldName1 dateType,add columns fieldName2 dateType;

多行命令輸入:注意不能將單詞斷開;當(dāng)插入或更改數(shù)據(jù)時,不能將字段的字符串展開到多行里,否則硬回車將被儲存到數(shù)據(jù)中;

增加一個管理員帳戶:grant all on *.* to user@localhost identified by "password";

每條語句輸入完畢后要在末尾填加分號';',或者填加'\g'也可以;

查詢時間:select now();

查詢當(dāng)前用戶:select user();

查詢數(shù)據(jù)庫版本:select version();

查詢當(dāng)前使用的數(shù)據(jù)庫:select database();

1、刪除student_course數(shù)據(jù)庫中的students數(shù)據(jù)表:

rm -f student_course/students.*

2、備份數(shù)據(jù)庫:(將數(shù)據(jù)庫test備份)

mysqldump -u root -p test>c:\test.txt

備份表格:(備份test數(shù)據(jù)庫下的mytable表格)

mysqldump -u root -p test mytable>c:\test.txt

將備份數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫:(導(dǎo)回test數(shù)據(jù)庫)

mysql -u root -p test

3、創(chuàng)建臨時表:(建立臨時表zengchao)

create temporary table zengchao(name varchar(10));

4、創(chuàng)建表是先判斷表是否存在

create table if not exists students(……);

5、從已經(jīng)有的表中復(fù)制表的結(jié)構(gòu)

create table table2 select * from table1 where 1<>1;

6、復(fù)制表

create table table2 select * from table1;

7、對表重新命名

alter table table1 rename as table2;

8、修改列的類型

alter table table1 modify id int unsigned;//修改列id的類型為int unsigned

alter table table1 change id sid int unsigned;//修改列id的名字為sid,而且把屬性修改為int unsigned

9、創(chuàng)建索引

alter table table1 add index ind_id (id);

create index ind_id on table1 (id);

create unique index ind_id on table1 (id);//建立唯一性索引

10、刪除索引

drop index idx_id on table1;

alter table table1 drop index ind_id;

11、聯(lián)合字符或者多個列(將列id與":"和列name和"="連接)

select concat(id,':',name,'=') from students;

12、limit(選出10到20條)

select * from students order by id limit 9,10;

13、MySQL不支持的功能

事務(wù),視圖,外鍵和引用完整性,存儲過程和觸發(fā)器

14、MySQL會使用索引的操作符號

=,>,=,between,in,不帶%或者_開頭的like

15、使用索引的缺點

1)減慢增刪改數(shù)據(jù)的速度;

2)占用磁盤空間;

3)增加查詢優(yōu)化器的負擔(dān);

當(dāng)查詢優(yōu)化器生成執(zhí)行計劃時,會考慮索引,太多的索引會給查詢優(yōu)化器增加工作量,導(dǎo)致無法選擇最優(yōu)的查詢方案;

16、分析索引效率

方法:在一般的SQL語句前加上explain;

分析結(jié)果的含義:

1)table:表名;

2)type:連接的類型,(ALL/Range/Ref)。其中ref是最理想的;

3)possible_keys:查詢可以利用的索引名;

4)key:實際使用的索引;

5)key_len:索引中被使用部分的長度(字節(jié));

6)ref:顯示列名字或者"const"(不明白什么意思);

7)rows:顯示MySQL認為在找到正確結(jié)果之前必須掃描的行數(shù);

8)extra:MySQL的建議;

17、使用較短的定長列

1)盡可能使用較短的數(shù)據(jù)類型;

2)盡可能使用定長數(shù)據(jù)類型;

a)用char代替varchar,固定長度的數(shù)據(jù)處理比變長的快些;

b)對于頻繁修改的表,磁盤容易形成碎片,從而影響數(shù)據(jù)庫的整體性能;

c)萬一出現(xiàn)數(shù)據(jù)表崩潰,使用固定長度數(shù)據(jù)行的表更容易重新構(gòu)造。使用固定長度的數(shù)據(jù)行,每個記錄的開始位置都是固定記錄長度的倍數(shù),可以很容易被檢測到,但是使用可變長度的數(shù)據(jù)行就不一定了;

d)對于MyISAM類型的數(shù)據(jù)表,雖然轉(zhuǎn)換成固定長度的數(shù)據(jù)列可以提高性能,但是占據(jù)的空間也大;

18、使用not null和enum

盡量將列定義為not null,這樣可使數(shù)據(jù)的出來更快,所需的空間更少,而且在查詢時,MySQL不需要檢查是否存在特例,即null值,從而優(yōu)化查詢;

如果一列只含有有限數(shù)目的特定值,如性別,是否有效或者入學(xué)年份等,在這種情況下應(yīng)該考慮將其轉(zhuǎn)換為enum列的值,MySQL處理的更快,因為所有的enum值在系統(tǒng)內(nèi)都是以標識數(shù)值來表示的;

19、使用optimize table

對于經(jīng)常修改的表,容易產(chǎn)生碎片,使在查詢數(shù)據(jù)庫時必須讀取更多的磁盤塊,降低查詢性能。具有可變長的表都存在磁盤碎片問題,這個問題對blob數(shù)據(jù)類 型更為突出,因為其尺寸變化非常大。可以通過使用optimize table來整理碎片,保證數(shù)據(jù)庫性能不下降,優(yōu)化那些受碎片影響的數(shù)據(jù)表。 optimize table可以用于MyISAM和BDB類型的數(shù)據(jù)表。實際上任何碎片整理方法都是用mysqldump來轉(zhuǎn)存數(shù)據(jù)表,然后使用轉(zhuǎn)存后的文件并重新建數(shù)據(jù) 表;

20、使用procedure analyse()

可以使用procedure analyse()顯示最佳類型的建議,使用很簡單,在select語句后面加上procedure analyse()就可以了;例如:

select * from students procedure analyse();

select * from students procedure analyse(16,256);

第二條語句要求procedure analyse()不要建議含有多于16個值,或者含有多于256字節(jié)的enum類型,如果沒有限制,輸出可能會很長;

21、使用查詢緩存

1)查詢緩存的工作方式:

第一次執(zhí)行某條select語句時,服務(wù)器記住該查詢的文本內(nèi)容和查詢結(jié)果,存儲在緩存中,下次碰到這個語句時,直接從緩存中返回結(jié)果;當(dāng)更新數(shù)據(jù)表后,該數(shù)據(jù)表的任何緩存查詢都變成無效的,并且會被丟棄。

2)配置緩存參數(shù):

變量:query_cache _type,查詢緩存的操作模式。有3中模式,0:不緩存;1:緩存查詢,除非與 select sql_no_cache開頭;2:根據(jù)需要只緩存那些以select sql_cache開頭的查詢; query_cache_size:設(shè)置查詢緩存的最大結(jié)果集的大小,比這個值大的不會被緩存。

22、調(diào)整硬件

1)在機器上裝更多的內(nèi)存;

2)增加更快的硬盤以減少I/O等待時間;

尋道時間是決定性能的主要因素,逐字地移動磁頭是最慢的,一旦磁頭定位,從磁道讀則很快;

3)在不同的物理硬盤設(shè)備上重新分配磁盤活動;

如果可能,應(yīng)將最繁忙的數(shù)據(jù)庫存放在不同的物理設(shè)備上,這跟使用同一物理設(shè)備的不同分區(qū)是不同的,因為它們將爭用相同的物理資源(磁頭)。

總結(jié)

以上是生活随笔為你收集整理的mysql库可以无限创建吗_mysql 创建库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。