mysql資料庫遷移

2021-08-28 17:25:32 字數 1188 閱讀 3751

伺服器資料庫遷移到新的資料庫中:

場景1、修改多個資料庫的字首以及表字首

1、建立資料庫

#根據規則建立新的資料庫

select

concat(

'create database ',

'new',

substring(schema_name, char_length('old_')),

' default charset ',default_character_set_name,

' collate ',default_collation_name,

';')

from

information_schema.schemata

where

schema_name like 'old_%';

#根據老的資料庫建立新的資料庫,保留字符集和規則,生成的語句形如:

create database new_product default charset utf8 collate utf8_general_ci;

#執行sql語句生成新的資料庫名稱

2、轉移資料庫表

運用資料傳輸工具直接傳輸資料

3、根據規則生成修改表的sql語句 (針對單個資料庫修改表)

select

concat(

'alter table ',

table_schema,

'.',

table_name,

' rename to ',

table_schema,

'.',

'new',

substring(table_name, char_length('ueb_')),

';') as '修改表字首sql'

from

information_schema.tables

where

table_schema = 'new_product' and table_name like 'old_%';

#執行生成的sql,如:

alter table new_product.old_test rename to new_product.new_test;

mysql庫遷移 mysql資料庫遷移

由於yum安裝mysql的時候,資料庫的data目錄預設是在 var lib下,出於資料安全性的考慮需要把它挪到 data分割槽。步驟如下 一 關閉apache和mysql.複製 如下 二 將 var lib下的mysql目錄mv 移動 到data目錄。為什麼要用mv命令,而不用cp命令呢?應為li...

MYSQL資料庫遷移

因為今天公司換了新電腦,所以需要把之前電腦的mysql資料庫遷移到新 電腦上 匯出整個資料庫 mysqldump u 使用者名稱 p 資料庫名 匯出的檔名 mysqldump u dbuser p dbname dbname.sql 一般要是沒指定檔案路徑則.sql檔案生成在cmd當前路徑下 匯入資...

MySQL資料庫遷移

mysql資料庫遷移 資料檔案直接遷移 在今年10月下旬的時候,公司的伺服器需要遷移,其中涉及到了mysql資料庫遷移。檢視了一下mysql資料檔案的大小,接近60g的大小 實際資料並沒用那麼多 由於伺服器上業務需要,要儘量減少伺服器遷移時的損失。所以遷移時間選在了晚上零點開始,而且要儘量減少遷移所...