共享表空间到独立表空间的转化流程
迁移步骤1:
show variables like ‘%per_table%’;
迁移步骤2:
service mysqld stop
迁移步骤3:
修改配置文件 innodb-file-per-table=1
迁移步骤4:
mysqldump 备份需要的数据 mysqldump -u -p –
–all-databases 所有数据库
-d 结构(–no-data:不导出任何数据,只导出数据库表结构)
-t 数据(–no-create-info:只导出数据,而不添加CREATE TABLE 语句)
-n (–no-create-db:只导出数据,而不添加CREATE DATABASE 语句)
-R (–routines:导出存储过程以及自定义函数)
-E (–events:导出事件)
–triggers (默认导出触发器,使用–skip-triggers屏蔽导出)
-B (–databases:导出数据库列表,单个库时可省略)
迁移步骤5:
删除使用innodb的数据库,以及日志文件 rm -f ib* 日志和空间 rm -rf 数据库文件夹
迁移步骤6:
service mysqld start
迁移步骤7:
还原数据
碎片整理脚本:
#!/bin/bash
mysql_user=xxxxx
mysql_pass=xxxxx
time_log=/opt/database/time
databases=/opt/database/databases
mysql -u$mysql_user -p$mysql_pass -e "show databases" | grep -v "Database" > $databases
sed -i "s/information_schema//" $databases
sed -i "s/mysql//" $databases
sed -i "s/test//" $databases
sed -i "s/performance_schema//" $databases
databases1=$(cat /opt/database/databases)
for i in $databases1
do
echo "database $i staring"
tables=$(mysql $i -u$mysql_user -p$mysql_pass -e "show tables" | grep -v "Tables" > /opt/database/$i)
tablelist=$(cat /opt/database/$i)
echo "optimize database $i starting" >> $time_log
echo "$i start at $(date +[%Y/%m/%d/%H/%M/%S])" >> $time_log
for list in $tablelist
do
echo $list
mysql $i -u$mysql_user -p$mysql_pass -e "alter table $list engine=InnoDB"
done
echo "$i end as $(date +[%Y/%m/%d/%H/%M/%S])" >> $time_log
echo >> $time_log
done