mysql 產生表檔案、truncate、Load,mysqltruncate
SELECT -- ' select * from `',TABLE_SCHEMA,'`.`',TABLE_NAME,'` into outfile ''/work/opdir/repair'''-- concat('union all -- select count(1) as count_, ''`',TABLE_SCHEMA,'`.`',TABLE_NAME, '`'' as tbname from `',TABLE_SCHEMA,'`.`',TABLE_NAME ,'`')-- as sql_CONCAT( ' select * from `',TABLE_SCHEMA,'`.`',TABLE_NAME,'` into outfile ''/work/opdir/repair/',TABLE_SCHEMA,'.',TABLE_NAME,'.tsv'' ; truncate table ' ,TABLE_SCHEMA,'.',TABLE_NAME,' ; LOAD DATA infile ''/work/opdir/repair/',TABLE_SCHEMA,'.',TABLE_NAME,'.tsv'' INTO TABLE ',TABLE_SCHEMA,'.',TABLE_NAME,' CHARACTER SET utf8; ')ExeSqlFROM information_schema.TABLES t WHERE t.TABLE_TYPE LIKE '%T%'AND t.TABLE_SCHEMA IN('BCReport_Sync'-- ,'AdConversions','AdSync','BCSourceData_Sync')AND t.`TABLE_NAME` NOT LIKE '%Log%'AND t.`TABLE_NAME` NOT LIKE '%bak%' AND t.`TABLE_NAME` NOT LIKE '%History%'AND t.`TABLE_NAME` NOT LIKE '%Tmp_%'AND t.`TABLE_NAME` NOT LIKE '%bak%'AND t.`TABLE_NAME` NOT LIKE '%Monitor%'AND t.`TABLE_NAME` NOT LIKE '%bak%'AND t.`TABLE_NAME` NOT LIKE '%backup%'AND t.`TABLE_NAME` NOT LIKE '%_BK'AND t.`TABLE_NAME` NOT LIKE '%_Temp'AND t.`TABLE_NAME` NOT LIKE '%2013%'AND t.`TABLE_NAME` NOT LIKE '%2'AND t.`TABLE_NAME` NOT LIKE '%2012%'AND t.`TABLE_NAME` NOT LIKE '%2012%'AND t.`TABLE_NAME` NOT LIKE '%2014%'AND CONCAT(t.TABLE_SCHEMA ,'.', t.`TABLE_NAME`) IN('AdConversions.DataInbound_TaskSchedule','AdConversions.DeviceForComparison','AdConversions.Fact_Realtime_Conversion','AdDataCenter.Ad_Account_Mirror','AdDataCenter.Ad_Account','AdDataCenter.Ad_AdGroup_AdAction_Mobisage','AdDataCenter.Ad_AdGroup_BidPrice','AdDataCenter.Ad_AdGroup_Property','AdDataCenter.Ad_AdGroup_WeekTimePeriod','AdDataCenter.Ad_AdGroup','AdDataCenter.Ad_Campaign_BudgetList','AdDataCenter.Ad_Campaign_DockingProduct_Mapping','AdDataCenter.Ad_Campaign_GeoTargeting','AdDataCenter.Ad_Campaign','AdDataCenter.Ad_Creative_Additional','AdDataCenter.Ad_Creative_ImageAd','AdDataCenter.Ad_Creative_Offerwall','AdDataCenter.Ad_Creative_Template','AdDataCenter.Ad_Creative','AdDataCenter.Ad_Targeting_Mobisage_AppIncluded','AdDataCenter.Ad_Targeting_Mobisage','AdDataCenter.Ad_Targeting','AdDataCenter.AdCreativeTemplate_SlotSize_Mapping','AdDataCenter.AdSync_AdCreative','AdDataCenter.App_MediaType_Mapping','AdDataCenter.AppOfferwall_Category_Mapping','AdDataCenter.Bill_AdAccount_Recharge_Daily','AdDataCenter.Bill_AdAccount_Spend_Daily','AdDataCenter.Dim_App','AdDataCenter.Dim_Slot','AdDataCenter.Docking_Product','AdDataCenter.Offerwall_AppBuckleScale_Mapping','AdDataCenter.Plugin_AdGroup','AdDataCenter.Slot_Affiliate_Business_Ratio','AdSync.Ad_Campaign_RealtimeControl','BCSourceData_Sync.Data_TaskSchedule','BCSourceData_Sync.Source_Fact_AccountHourlySpend','BCSourceData_Sync.Source_Fact_AdCreative_App_Usage_ThirdPartPlatform')
我用的是mysql,部分表中沒有主外鍵,當我使用 truncate命令清空這些表時,不可以清空,
有外鍵串連的表貌似不能直接清空資料。。不知道你具體表結構我也不好說。。
mysql的truncate 命令與count 命令的傳回值是不是應該相同的?
你資料庫 可以看看嗎 注意下面 2個刪除語句的區別
TRUNCATE和DELETE有以下幾點區別
1、TRUNCATE在各種表上無論是大的還是小的都非常快。如果有ROLLBACK命令DELETE將被撤銷,而TRUNCATE則不會被撤銷。
2、TRUNCATE是一個DDL語言,向其他所有的DDL語言一樣,他將被隱式提交,不能對TRUNCATE使用ROLLBACK命令。
3、TRUNCATE將重新設定高水平線和所有的索引。在對整個表和索引進行完全瀏覽時,經過TRUNCATE操作後的表比DELETE操作後的表要快得多。
4、TRUNCATE不能觸發任何DELETE觸發器。
5、不能授予任何人清空他人的表的許可權。
6、當表被清空後表和表的索引講重新設定成初始大小,而delete則不能。
7、不能清空父表。