innodb 共享表空间 转 独立表空间 详细说明,以及遇到的问题[转]

innodb 共享表空间 转 独立表空间 详细说明,以及遇到的问题
张映 发表于 2011-12-31
分类目录: mysql
最近在优化mysql innodb存储引擎,准备把共享表空间转换成独立表空间。刚开始的没考虑这么多,过段时间又要推广,所以优化一下,看看效果如何。说一个转换过程。
1,查看一下是共享表空间,还是独立表空间
查看复制打印?
mysql> show variables like '%per_table%'; 
+-----------------------+-------+ 
| Variable_name         | Value | 
+-----------------------+-------+ 
| innodb_file_per_table | OFF   | 
+-----------------------+-------+ 
1 row in set (0.00 sec) 
如果是OFF,肯定不是独立表空间。如果是ON的话,也不一定是独立表空间。最直接的方法就是查看硬盘上的文件,独立表空间,每个表都对应了一个空间。
[root@localhost tg]# ll 
总用量 64 
-rw-rw----. 1 mysql mysql   65 12月 30 20:09 db.opt 
-rw-rw----. 1 mysql mysql 8658 12月 30 23:17 gb.frm 
-rw-rw----. 1 mysql mysql 8658 12月 30 23:19 qr.frm 
-rw-rw----. 1 mysql mysql 8658 12月 30 23:19 qy.frm 
-rw-rw----. 1 mysql mysql 8658 12月 30 23:19 tg.frm 
-rw-rw----. 1 mysql mysql 8658 12月 30 23:19 xcy.frm 
tg是一个数据库名,里面的都是innodb的。像这种情况就是共享表空间。
2,停掉mysql
/etc/init.d/mysqld stop 
3,修改my.cnf的配置文件
innodb-file-per-table=1 
4,备份使用innodb引擎的数据库
mysqldump -u tg -p tg >/home/6fan/tg.sql; 
5,删除使用innodb的数据库,以及日志文件
查看复制打印?
cd /var/lib/mysql    //数据库文件位置 
 
rm -f ib*           //删除日志和空间 
 
rm -rf tg           //删除使用innodb引擎的数据库文件夹 
如果不删除使用innodb的数据库文件夹,启动不了innodb引擎,我查看了一下错误日志。如下
111231 20:54:44 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 512 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200 300 400 500
111231 20:54:50 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 512 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200 300 400 500
InnoDB: Cannot initialize created log files because
InnoDB: data files are corrupt, or new data files were
InnoDB: created when the database was started previous
InnoDB: time but the database was not shut down
InnoDB: normally after that.
111231 20:54:55 [ERROR] Plugin 'InnoDB' init function returned error.
111231 20:54:55 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
111231 20:54:55 [Note] Event Scheduler: Loaded 0 events
6,启动mysql
/etc/init.d/mysqld start 
7,导入数据库
mysql -u root -p  < /home/6fan/tg.sql 
8,在查看一下,是转换好了
查看复制打印?
//进入到mysql后的查寻 
mysql> show variables like '%per_table%'; 
+-----------------------+-------+ 
| Variable_name         | Value | 
+-----------------------+-------+ 
| innodb_file_per_table | ON   | 
+-----------------------+-------+ 
1 row in set (0.00 sec) 
 
//查看数据库目录下的文件 
[root@localhost tg]# ll 
总用量 544 
-rw-rw----. 1 mysql mysql    65 12月 31 22:48 db.opt 
-rw-rw----. 1 mysql mysql  8658 12月 31 22:49 gb.frm 
-rw-rw----. 1 mysql mysql 98304 12月 31 22:49 gb.ibd 
-rw-rw----. 1 mysql mysql  8658 12月 31 22:49 qr.frm 
-rw-rw----. 1 mysql mysql 98304 12月 31 22:49 qr.ibd 
-rw-rw----. 1 mysql mysql  8658 12月 31 22:49 qy.frm 
-rw-rw----. 1 mysql mysql 98304 12月 31 22:49 qy.ibd 
-rw-rw----. 1 mysql mysql  8658 12月 31 22:49 tg.frm 
-rw-rw----. 1 mysql mysql 98304 12月 31 22:49 tg.ibd 
-rw-rw----. 1 mysql mysql  8658 12月 31 22:49 xcy.frm 
-rw-rw----. 1 mysql mysql 98304 12月 31 22:49 xcy.ibd 
从这里可以看出,每一张表都对应有一个.ibd的文件,根共享表空间是不一样的。到这儿就完全配置好了。
收藏、分享这篇文章!
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/mysql/1368.html

猜你喜欢

转载自omyyal.iteye.com/blog/1634030