將phpstudy中的mysql遷移至Linux教程
項(xiàng)目目的
將原來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
遷移過程
1.使用phpstudy自帶的工具進(jìn)行每個(gè)數(shù)據(jù)庫導(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ù)庫中的表引擎變更為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ù)庫
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è)問題,查看表的詳細(xì)信息時(shí)發(fā)現(xiàn)Data_free不為零,說明存在數(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ù)庫方法同樣操作即可。
相關(guān)文章
Ubuntu下取消MySQL數(shù)據(jù)庫本機(jī)綁定限制方法
在Ubuntu系統(tǒng)中,添加了MySQL賬戶,賦予了數(shù)據(jù)庫完全操作權(quán)限,并且允許數(shù)據(jù)庫從外部鏈接 但是,還是無法遠(yuǎn)程訪問MySQL數(shù)據(jù)庫2013-06-06詳解數(shù)據(jù)庫_MySQL: mysql函數(shù)
這篇文章主要介紹了數(shù)據(jù)庫_MySQL: mysql函數(shù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03Mysql系列SQL查詢語句書寫順序及執(zhí)行順序詳解
這篇文章主要為大家介紹了Mysql系列SQL查詢語句的書寫順序及執(zhí)行順序示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-10-10mysql如何對已經(jīng)加密的字段進(jìn)行模糊查詢詳解
對于密碼等信息可以采用單向加密,驗(yàn)證的時(shí)候用同樣的方式加密匹配即可,下面這篇文章主要給到家介紹了關(guān)于mysql如何對已經(jīng)加密的字段進(jìn)行模糊查詢的相關(guān)資料,需要的朋友可以參考下2022-09-09MySQL 導(dǎo)出數(shù)據(jù)為csv格式的方法
這篇文章主要介紹了MySQL 導(dǎo)出數(shù)據(jù)為csv格式的方法,需要的朋友可以參考下2015-10-10利用pt-heartbeat監(jiān)控MySQL的復(fù)制延遲詳解
這篇文章主要給大家介紹了利用pt-heartbeat監(jiān)控MySQL的復(fù)制延遲的相關(guān)資料,文中詳細(xì)介紹了pt-heartbeat、監(jiān)控原理以及安裝過程等的相關(guān)內(nèi)容,對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-06-06