Mysql
mysql backup
usage
#mysqldump [options] db_name [tables]
#mysqldump [options] –databases db_name1 [db_name2 db_name3...]
#mysqldump [options] –all-databases
Example
#mysqldump -u root -p mydatabase > db.sql
Specific table
#mysqldump -u root -p mydatabase -tables customer > db.sql
How to restore database
#mysql -u root -p database < db.sql
If want to restore to specific database
mysql -u root -pMyPassword MyDatabase < db.sql
MYSQL limit Optimization-2
The MYSQL optimization is very important. Other most commonly used also most need to optimize are limit. mysql limit has brought enormous convenient to the paging, but the data quantity one is big, the limit performance suddenly drops.
Similarly takes 10 data
select * from temp limit 10000,10
and
select * from temp limit 0,10
It is not a quantity rank.
Now many about limit five optimized criterion, is from the mysql handbook ,You may have a look at this article about Mysql limit:http://www.easemarry.com/blog/mysql-limit-optimization/
In the article uses limit directly, but first gains to offset id then uses limit size to gain the data directly. According to his data, is friends with obviously in uses limit directly. Here my concrete service data is divided two kind of situations to carry on the test.
1st, offset small time.
select * from temp limit 10,10
Repeatedly running , the time maintains between 0.0004-0.0005
Select * From yanxue8_visit Where vid >=(
Select vid From yanxue8_visit Order By vid limit 10,1
) limit 10
Repeatedly running , the time maintains between 0.0005-0.0006
Conclusion: offset is small, uses limit to be superior directly. This is the sub-inquiry reason obviously.
2nd, offset great time.
select * from temp limit 10000,10
Repeatedly running , the time maintains between 0.0185-0.0190
Select * From yanxue8_visit Where vid >=(
Select vid From yanxue8_visit Order By vid limit 10000,1
) limit 10
Repeatedly running , the time maintains between 0.0061-0.0065,Only the former 1/3. May estimate that offset is bigger, the latter is more superior.
http://www.easemarry.com/blog
MYSQL limit Optimization
select * from table LIMIT 5,10; #return to 6-15th line
select * from table LIMIT 5; #return to 0-5 line
select * from table LIMIT 0,5; #return to 0-5 line
Performance optimization:
In MySQL5.0 limit high performance.
1.
Select * From cyclopedia Where ID>=(
Select Max(ID) From (
Select ID From cyclopedia Order By ID limit 90001
) As tmp
) limit 100;
2.
Select * From cyclopedia Where ID>=(
Select Max(ID) From (
Select ID From cyclopedia Order By ID limit 90000,1
) As tmp
) limit 100;
Similarly takes 90000 latter 100 records, 1st quickly 2nd quick?
1st has preoccupied the first 90001 records, takes is biggest a ID value to take outset marking, then uses it to be possible fast localization next 100 record
Very obvious 2nd wins. Before looking like limit probably looks like me, not completely imagines such makes the entire table scanning to return to limit the offset+length strip record, this way limit compares MS-SQL Top the performance to enhance many.
Actually 2nd definitely may revise:
Select * From cyclopedia Where ID>=(
Select ID From cyclopedia limit 90000,1
)limit 100;
Uses the 90000th record directly ID, does not need to undergo the Max operation, because like this makes theoretically the efficiency this high somewhat, but does not look at the effect nearly in the actual use, because itself locates the ID returns is 1 record, Max does not need the operation to be able nearly to obtain the result.
But, since MySQL has limit to be possible the positive governing to take out the record the position, why not simply uses Select * From cyclopedia limit 90000,1? To be how could it not be more succinct? wanted mistakenly, to try like this to know that the result was: 1 row in set (8.88) sec, what kind, suffices scary, let me remember yesterday compared this in 4.1 also to have ” the high score “. Select * should better not use casually, must in line with use anything, chooses anything the principle, the Select field to be more, the field data quantity is bigger, the speed is slower. Have above 2 kind of paging mode which kind 1 strong been more than Shan Xiezhei, although looks like the number of times which probably inquires to be more some, but in fact has received in exchange for the highly effective performance by the small price, was worth.
The 1st kind of plan may use in MS-SQL similarly, moreover possibly is best. Because locates the initial sector depending on principal linkage ID to be always quickest.
Select Top 100 * From cyclopedia Where ID>=(
Select Top 90001 Max(ID) From (
Select ID From cyclopedia Order By ID
) As tmp
)
But no matter realizes the way to PROCEDURE or code, the bottleneck lies in MS-SQL TOP always to throughout return to the first N record, this kind of situation when the data quantity is not big feels not deeply, but if hundred and thousand of ten thousand, the efficiency can definitely be low. Comparatively MySQL limit has superiority many, the execution:
Select ID From cyclopedia limit 90000
Select ID From cyclopedia limit 90000,1
result respectively is:
90000 rows in set (0.36) sec
1 row in set (0.06) sec
But MS-SQL can only use Select Top 90000 ID From the cyclopedia execution time is 390ms, carries out the similar operating time also to be inferior to MySQL 360ms.

