将phpstudy中的mysql迁移至Linux教程
项目目的
将原来windows环境中使用phpstudy搭建的mysql5.5.53中的数据迁移至新主机Linux环境中
环境情况
新主机
系统平台:
CentOSrelease7.4(Final) 内核 3.10.0-693.el7.x86_64
mysql环境:
mysql>status
Serverversion: 5.6.39-logMySQLCommunityServer(GPL)
Servercharacterset: utf8
Db characterset: utf8
Clientcharacterset: utf8
Conn. characterset: utf8
mysql>showvariableslike'%storage_engine%';
+----------------------------+--------+
|Variable_name |Value |
+----------------------------+--------+
|default_storage_engine |InnoDB|
|default_tmp_storage_engine|InnoDB|
|storage_engine |InnoDB|
+----------------------------+--------+
旧主机:
系统平台:
Windows2012R2SEX64
mysql环境:
Serverversion: 5.5.53MySQLCommunityServer(GPL)
Servercharacterset: utf8
Db characterset: utf8
Clientcharacterset: utf8
Conn. characterset: utf8
mysql>showvariableslike'%storage_engine%';
+------------------------+--------+
|Variable_name |Value |
+------------------------+--------+
|default_storage_engine|MyISAM|
|storage_engine |MyISAM|
+------------------------+--------+
表的存储引擎
mysql>showtablestatusfromdatabase\G;
Engine:InnoDB
Engine:MyISAM
迁移过程
1.使用phpstudy自带的工具进行每个数据库导出
image
我看了,也是用的mysqldump操作的。
2.如果只是保留原本的表引擎,那么直接以下操作即可
mysql>createdatabasezentao;
mysql>usezentao;
mysql>sourcezentao20180413161534.sql;
mysql>showtables;
+-------------------+
|Tables_in_zentao |
+-------------------+
|zt_action |
|zt_bug |
|zt_build |
...
原表引擎保持原样。
mysql>showtablestatusfromzentao\G;
***************************1.row***************************
Name:zt_action
Engine:MyISAM
Version:10
Row_format:Dynamic
3.将原有数据库中的表引擎变更为InnoDB
在导出的表结构zentao.sql中找到ENGINE=MyISAM,修改成ENGINE=InnoDB,至于你用什么方法替换,看你喜欢了。
#vimzentao.sql
:%s/ENGINE=MyISAM/ENGINE=InnoDB/g
4.导入数据到指定数据库
mysql>usezentao;
mysql>sourcezentao.sql;
表引擎变更为InnoDB
mysql>showtablestatusfromzentao\G;
***************************1.row***************************
Name:zt_action
Engine:InnoDB
Version:10
Row_format:Compact
5.但是有一个问题,查看表的详细信息时发现Data_free不为零,说明存在数据碎片,需要进行优化
mysql>selecttable_schema,table_name,data_free,enginefrominformation_schema.tableswheretable_schemanotin('information_schema','mysql')anddata_free!=0;
+--------------+------------+-----------+--------+
|table_schema|table_name|data_free|engine|
+--------------+------------+-----------+--------+
|zentao |zt_bug | 4194304|InnoDB|
|zentao |zt_history| 4194304|InnoDB|
+--------------+------------+-----------+--------+
6.整理有碎片的表
mysql>usezentao;
mysql>optimizetablezt_bug,zt_history;
+-------------------+----------+----------+-------------------------------------------------------------------+
|Table |Op |Msg_type|Msg_text |
+-------------------+----------+----------+-------------------------------------------------------------------+
|zentao.zt_bug |optimize|note |Tabledoesnotsupportoptimize,doingrecreate+analyzeinstead|
|zentao.zt_bug |optimize|status |OK |
|zentao.zt_history|optimize|note |Tabledoesnotsupportoptimize,doingrecreate+analyzeinstead|
|zentao.zt_history|optimize|status |OK |
+-------------------+----------+----------+-------------------------------------------------------------------+
提示该表不支持optimize,但是下边有显示OK.其实已经执行成功了。5.6.X的版本,其实已经支持Innodb了
mysql>selecttable_name,engine,table_rows,data_length+index_lengthlength,DATA_FREEfrominformation_schema.tableswhereTABLE_SCHEMA='zentao'anddata_free=0;
+-------------------+--------+------------+---------+-----------+
|table_name |engine|table_rows|length |DATA_FREE|
+-------------------+--------+------------+---------+-----------+
|zt_bug |InnoDB| 1018|1589248| 0|
|zt_history |InnoDB| 2584|1589248| 0|
多个数据库方法同样操作即可。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。