项目目的

将原来windows环境中使用phpstudy搭建的mysql 5.5.53 中的数据迁移至新主机Linux环境中

环境情况

新主机
系统平台:

CentOS release 7.4 (Final) 内核 3.10.0-693.el7.x86_64

mysql环境:

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 |
+----------------------------+--------+

旧主机:
系统平台:

Windows 2012 R2 SE X64

mysql环境:

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 |
+------------------------+--------+

表的存储引擎

mysql> show table status from database\G;
Engine: InnoDB
Engine: MyISAM

迁移过程

1.使用phpstudy自带的工具进行每个数据库导出

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.将原有数据库中的表引擎变更为InnoDB

在导出的表结构zentao.sql中找到ENGINE=MyISAM,修改成ENGINE=InnoDB,至于你用什么方法替换,看你喜欢了。

# vim zentao.sql
:%s/ENGINE=MyISAM/ENGINE=InnoDB/g

4.导入数据到指定数据库

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.但是有一个问题,查看表的详细信息时发现Data_free不为零,说明存在数据碎片,需要进行优化

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.其实已经执行成功了。5.6.X的版本,其实已经支持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 |

多个数据库方法同样操作即可。

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Pycharm安装PyQt5的详细教程
  3. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  4. android用户界面之按钮(Button)教程实例汇
  5. 【Android(安卓)开发教程】Toast通知
  6. Android简易实战教程--第三十九话《Chronometer实现倒计时》
  7. android加密解密完美教程
  8. Android(安卓)SDK自带教程之BluetoothChat
  9. OpenGL ES教程VI之纹理贴图(原文对照)

随机推荐

  1. Android多种View动画:EasyAndroidAnimatio
  2. Android点击2次退出
  3. android讲义2之在xml中设定imageButtion
  4. Android 直接打开log的一种方法
  5. android中广播接收者BroadcastReceiver
  6. Android中WebView加载网页设置进度条
  7. Android—将Bitmap图片保存到SD卡目录下
  8. android Intent.FLAG大全
  9. Android设置Listview每个item的间距
  10. Android(安卓)通讯录学习笔记之——调用