zoukankan      html  css  js  c++  java
  • innodb 共享表空间 转 独立表空间 详细说明,以及遇到的问题

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

    张映 发表于 2011-12-31

    分类目录: mysql

    最近在优化mysql innodb存储引擎,准备把共享表空间转换成独立表空间。刚开始的没考虑这么多,过段时间又要推广,所以优化一下,看看效果如何。说一个转换过程。

    1,查看一下是共享表空间,还是独立表空间

    1. mysql> show variables like '%per_table%';  
    2. +-----------------------+-------+  
    3. | Variable_name         | Value |  
    4. +-----------------------+-------+  
    5. | innodb_file_per_table | OFF   |  
    6. +-----------------------+-------+  
    7. 1 row in set (0.00 sec)  

    如果是OFF,肯定不是独立表空间。如果是ON的话,也不一定是独立表空间。最直接的方法就是查看硬盘上的文件,独立表空间,每个表都对应了一个空间。

    1. [root@localhost tg]# ll  
    2. 总用量 64  
    3. -rw-rw----. 1 mysql mysql   65 12月 30 20:09 db.opt  
    4. -rw-rw----. 1 mysql mysql 8658 12月 30 23:17 gb.frm  
    5. -rw-rw----. 1 mysql mysql 8658 12月 30 23:19 qr.frm  
    6. -rw-rw----. 1 mysql mysql 8658 12月 30 23:19 qy.frm  
    7. -rw-rw----. 1 mysql mysql 8658 12月 30 23:19 tg.frm  
    8. -rw-rw----. 1 mysql mysql 8658 12月 30 23:19 xcy.frm  

    tg是一个数据库名,里面的都是innodb的。像这种情况就是共享表空间。

    2,停掉mysql

    1. /etc/init.d/mysqld stop  

    3,修改my.cnf的配置文件

    1. innodb-file-per-table=1  

    4,备份使用innodb引擎的数据库

    1. mysqldump -u tg -p tg >/home/6fan/tg.sql;  

    5,删除使用innodb的数据库,以及日志文件

    1. cd /var/lib/mysql    //数据库文件位置  
    2.   
    3. rm -f ib*           //删除日志和空间  
    4.   
    5. 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

    1. /etc/init.d/mysqld start  

    7,导入数据库

    1. mysql -u root -p  < /home/6fan/tg.sql  

    8,在查看一下,是转换好了

    1. //进入到mysql后的查寻  
    2. mysql> show variables like '%per_table%';  
    3. +-----------------------+-------+  
    4. | Variable_name         | Value |  
    5. +-----------------------+-------+  
    6. | innodb_file_per_table | ON   |  
    7. +-----------------------+-------+  
    8. 1 row in set (0.00 sec)  
    9.   
    10. //查看数据库目录下的文件  
    11. [root@localhost tg]# ll  
    12. 总用量 544  
    13. -rw-rw----. 1 mysql mysql    65 12月 31 22:48 db.opt  
    14. -rw-rw----. 1 mysql mysql  8658 12月 31 22:49 gb.frm  
    15. -rw-rw----. 1 mysql mysql 98304 12月 31 22:49 gb.ibd  
    16. -rw-rw----. 1 mysql mysql  8658 12月 31 22:49 qr.frm  
    17. -rw-rw----. 1 mysql mysql 98304 12月 31 22:49 qr.ibd  
    18. -rw-rw----. 1 mysql mysql  8658 12月 31 22:49 qy.frm  
    19. -rw-rw----. 1 mysql mysql 98304 12月 31 22:49 qy.ibd  
    20. -rw-rw----. 1 mysql mysql  8658 12月 31 22:49 tg.frm  
    21. -rw-rw----. 1 mysql mysql 98304 12月 31 22:49 tg.ibd  
    22. -rw-rw----. 1 mysql mysql  8658 12月 31 22:49 xcy.frm  
    23. -rw-rw----. 1 mysql mysql 98304 12月 31 22:49 xcy.ibd  

    从这里可以看出,每一张表都对应有一个.ibd的文件,根共享表空间是不一样的。到这儿就完全配置好了。

  • 相关阅读:
    Spring MVC 核心组件详解
    Spring MVC 入门就这一篇
    Spring 事务解决方案
    【UGUI源码分析】Unity遮罩之Mask详细解读
    游戏开发中不同时区下的时间问题
    ARTS第十三周(阅读Tomcat源码)
    Win10 电脑安装.NET低版本提示“这台计算机中已经安装了 .NET Framwork 4.6.2或版本更高的更新”问题
    Dynamics 365 Setup 提示SqlServer 存在
    Dynamics CRM "Verification of prerequisites for Domain Controller promotion failed. Certificate Server is installed."
    Dynamics CRM
  • 原文地址:https://www.cnblogs.com/breg/p/2421307.html
Copyright © 2011-2022 走看看