新聞中心
mysql一個(gè)表大量數(shù)據(jù),現(xiàn)在要按分成多個(gè)表,怎么把數(shù)據(jù)分出來(lái)
一條語(yǔ)句沒(méi)法實(shí)現(xiàn)的...
創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的紅崗網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
create table table2 select * from table1 order by id limit 1,100
create table table3 select * from table1 order by id limit 100,100
create table table4 select * from table1 order by id limit 200,100
mysql數(shù)據(jù)庫(kù)一表拆分多表
呵呵,這個(gè)還不好辦么,你寫(xiě)的語(yǔ)句類似這個(gè)吧 我用C++語(yǔ)法給你寫(xiě)吧,希望能給你點(diǎn)提示
int a;
a=x_id%9
CString tbl_name
tbl_name="A_"+a;
CString Sql;
Sql="select * from" + tblname;
MySQL 對(duì)于大表,要怎么優(yōu)化
1、做分區(qū)表,(哪個(gè)字段分區(qū)很重要,分錯(cuò)會(huì)影響性能)。
2、拆表,
可以將歷史數(shù)據(jù)放到 其他表中,例如 abc表中,2013年的數(shù)據(jù),拆到 abc_2013表中,2014年的數(shù)據(jù)拆到abc_2014表中。
MySQL拆表遇到的問(wèn)題:相同用戶的多條數(shù)據(jù)分布在拆前后的多個(gè)表中,需要類似GROUP BY的篩選效果~
SELECT MAX(login_time) AS login_time,user_id
FROM(
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record GROUP BY user_id
UNION
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record_20170101 GROUP BY user_id
UNION
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record_20180101 GROUP BY user_id
)TMP GROUP BY user_id
MYSQL命令怎么實(shí)現(xiàn)將表中某個(gè)字段中多個(gè)記錄拆分,急求答案!
覺(jué)得你還是應(yīng)該用php去寫(xiě)。非要用mysql本身的話給個(gè)參考:
mysql?select?*?from?a;
+------+--------+------+----+
|?id???|?name???|?num1?|?bb?|
+------+--------+------+----+
|????1?|?a,?????|????2?|??3?|
|????2?|?b,c,???|????2?|??4?|
|????3?|?d,e,f,?|????2?|??5?|
+------+--------+------+----+
3?rows?in?set?(0.00?sec)
mysql?delimiter?//
mysql?create?procedure?`strsplit1`(in?str3?varchar(2))
-?begin
-??declare?i?int(10);
-??declare?j?int(10);
-??declare?k?int(10);
-??declare?str1?varchar(100);
-?????????declare?str4?varchar(1000);
-??declare?str5?varchar(100);
-
-??select?count(*)?into?i?from?a;
-??if?i!=0?then
-??????????drop?table?if?exists?tmp_table1;
-??????????CREATE?TEMPORARY?TABLE?tmp_table1?like?a;
-??end?if;
-
-??set?j=0;
-??while?ji?do
-??????????select?id,name?into?str1,str4?from?a?limit?j,1;
-??????????select?instr(str4,str3)?into?k?from?dual;
-??????????if?k=0?then
-??????????????????insert?into?tmp_table1(id,name)?values(str1,str4);
-??????????end?if;
-??????????while?k!=0?do
-??????????????????select?substring_index(str4,str3,1)?into?str5?from?dual;
-??????????????????insert?into?tmp_table1(id,name)?values(str1,str5);
-??????????????????select?mid(str4,k+1)?into?str4?from?dual;
-??????????????????select?instr(str4,str3)?into?k?from?dual;
-??????????end?while;
-??set?j=j+1;
-??end?while;
-
-?select?*?from?tmp_table1;
-?end
-?//
Query?OK,?0?rows?affected?(0.00?sec)
mysql??delimiter?;
最后結(jié)果:
mysql?call?strsplit1(',');
+------+------+------+----+
|?id???|?name?|?num1?|?bb?|
+------+------+------+----+
|????1?|?a????|?NULL?|??1?|
|????2?|?b????|?NULL?|??2?|
|????2?|?c????|?NULL?|??3?|
|????3?|?d????|?NULL?|??4?|
|????3?|?e????|?NULL?|??5?|
|????3?|?f????|?NULL?|??6?|
+------+------+------+----+
6?rows?in?set?(0.25?sec)
Query?OK,?0?rows?affected?(0.30?sec)
mysql 單邊300W數(shù)據(jù)是否建議拆表
三百萬(wàn)左右的數(shù)據(jù),說(shuō)大不大,說(shuō)小也不小了。
這個(gè)數(shù)據(jù)量,做好索引的話,暫時(shí)還不需要拆表存儲(chǔ)。
不過(guò)考慮以后還會(huì)有大量數(shù)據(jù)存入的話,你可以做一下拆表計(jì)劃了。
新聞名稱:mysql怎么拆表,mysql改表
轉(zhuǎn)載注明:http://www.dlmjj.cn/article/dsgisjj.html