zoukankan      html  css  js  c++  java
  • innodb 修改表共享空间为独立空间

    最近在优化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的文件,根共享表空间是不一样的。到这儿就完全配置好了。

  • 相关阅读:
    VS.NET2013发布网站的时候去掉.cs文件(预编译)(转)
    vs2013发布网站合并程序是出错(ILmerge.merge:error)
    转:c# Linq 的分页[转]
    AStar 路径规划之初级二
    ASttar 路径规划之初级
    AttributeError: module 'tensorflow' has no attribute 'set_random_seed'
    github提示Permission denied (publickey),如何才能解决?
    机器学习-模型评价指标
    pcl-qt使用QVTKWidget 与PCLVisualizer 显示雷达点云
    pcl-设置多线段宽度和颜色
  • 原文地址:https://www.cnblogs.com/naledao/p/3417241.html
Copyright © 2011-2022 走看看