項(xiàng)目目的
將原來(lái)windows環(huán)境中使用phpstudy搭建的mysql 5.5.53 中的數(shù)據(jù)遷移至新主機(jī)Linux環(huán)境中
環(huán)境情況
新主機(jī)
系統(tǒng)平臺(tái):
CentOS release 7.4 (Final) 內(nèi)核 3.10.0-693.el7.x86_64
mysql環(huán)境:
mysql> status
Server version: 5.6.39-log MySQL Community Server (GPL)
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
mysql> show variables like '%storage_engine%';
+----------------------------+--------+
| Variable_name | Value |
+----------------------------+--------+
| default_storage_engine | InnoDB |
| default_tmp_storage_engine | InnoDB |
| storage_engine | InnoDB |
+----------------------------+--------+
舊主機(jī):
系統(tǒng)平臺(tái):
Windows 2012 R2 SE X64
mysql環(huán)境:
Server version: 5.5.53 MySQL Community Server (GPL)
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
mysql> show variables like '%storage_engine%';
+------------------------+--------+
| Variable_name | Value |
+------------------------+--------+
| default_storage_engine | MyISAM |
| storage_engine | MyISAM |
+------------------------+--------+
表的存儲(chǔ)引擎
mysql> show table status from database\G;
Engine: InnoDB
Engine: MyISAM
遷移過(guò)程
1.使用phpstudy自帶的工具進(jìn)行每個(gè)數(shù)據(jù)庫(kù)導(dǎo)出
image
我看了,也是用的mysqldump操作的。
2.如果只是保留原本的表引擎,那么直接以下操作即可
mysql> create database zentao;
mysql> use zentao;
mysql> source zentao20180413161534.sql;
mysql> show tables;
+-------------------+
| Tables_in_zentao |
+-------------------+
| zt_action |
| zt_bug |
| zt_build |
...
原表引擎保持原樣。
mysql> show table status from zentao\G;
*************************** 1. row ***************************
Name: zt_action
Engine: MyISAM
Version: 10
Row_format: Dynamic
3.將原有數(shù)據(jù)庫(kù)中的表引擎變更為InnoDB
在導(dǎo)出的表結(jié)構(gòu)zentao.sql中找到ENGINE=MyISAM,修改成ENGINE=InnoDB,至于你用什么方法替換,看你喜歡了。
# vim zentao.sql
:%s/ENGINE=MyISAM/ENGINE=InnoDB/g
4.導(dǎo)入數(shù)據(jù)到指定數(shù)據(jù)庫(kù)
mysql> use zentao;
mysql> source zentao.sql;
表引擎變更為InnoDB
mysql> show table status from zentao\G;
*************************** 1. row ***************************
Name: zt_action
Engine: InnoDB
Version: 10
Row_format: Compact
5.但是有一個(gè)問(wèn)題,查看表的詳細(xì)信息時(shí)發(fā)現(xiàn)Data_free不為零,說(shuō)明存在數(shù)據(jù)碎片,需要進(jìn)行優(yōu)化
mysql> select table_schema, table_name, data_free, engine from information_schema.tables where table_schema not in ('information_schema', 'mysql') and data_free != 0;
+--------------+------------+-----------+--------+
| table_schema | table_name | data_free | engine |
+--------------+------------+-----------+--------+
| zentao | zt_bug | 4194304 | InnoDB |
| zentao | zt_history | 4194304 | InnoDB |
+--------------+------------+-----------+--------+
6.整理有碎片的表
mysql> use zentao;
mysql> optimize table zt_bug,zt_history;
+-------------------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-------------------+----------+----------+-------------------------------------------------------------------+
| zentao.zt_bug | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| zentao.zt_bug | optimize | status | OK |
| zentao.zt_history | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| zentao.zt_history | optimize | status | OK |
+-------------------+----------+----------+-------------------------------------------------------------------+
提示該表不支持 optimize,但是下邊有顯示OK.其實(shí)已經(jīng)執(zhí)行成功了。5.6.X的版本,其實(shí)已經(jīng)支持Innodb了
mysql> select table_name,engine,table_rows,data_length+index_length length,DATA_FREE from information_schema.tables where TABLE_SCHEMA='zentao' and data_free =0;
+-------------------+--------+------------+---------+-----------+
| table_name | engine | table_rows | length | DATA_FREE |
+-------------------+--------+------------+---------+-----------+
| zt_bug | InnoDB | 1018 | 1589248 | 0 |
| zt_history | InnoDB | 2584 | 1589248 | 0 |
多個(gè)數(shù)據(jù)庫(kù)方法同樣操作即可。
您可能感興趣的文章:- 完美解決phpstudy安裝后mysql無(wú)法啟動(dòng)(無(wú)需刪除原數(shù)據(jù)庫(kù),無(wú)需更改任何配置,無(wú)需更改端口)直接共存
- phpstudy2018升級(jí)MySQL5.5為5.7教程(圖文)
- phpStudy中升級(jí)MySQL版本到5.7.17的方法步驟
- Windows系統(tǒng)下解決PhPStudy MySQL啟動(dòng)失敗問(wèn)題