Home>Article>Database> Mysql replaces MyISAM storage engine with Innodb operation record sample code sharing

Mysql replaces MyISAM storage engine with Innodb operation record sample code sharing

黄舟
黄舟 Original
2017-03-23 13:40:23 1401browse

The following editor will bring you a summary of the operation records ofMysqlchanging the MyISAM storage engine to Innodb. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look.

Under normal circumstances, mysql will provide multiple storage engines by default, which can be viewed through the following:

1) Check whether mysqlhas the innodb plug-in installed.

#It can be seen from the following command results that the innodb plug-in has been installed.

mysql> show plugins; +------------+--------+----------------+---------+---------+ | Name | Status | Type | Library | License | +------------+--------+----------------+---------+---------+ | binlog | ACTIVE | STORAGE ENGINE | NULL | GPL | | partition | ACTIVE | STORAGE ENGINE | NULL | GPL | | CSV | ACTIVE | STORAGE ENGINE | NULL | GPL | | MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL | | InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL | | MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | | MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL | +------------+--------+----------------+---------+---------+ 7 rows in set (0.00 sec)

---------------------------------------- ----------------------------------If you find that the innodb plug-in is not installed, you can execute the following statement to install it:

mysql> install plugin innodb soname 'ha_innodb.so';

------------------------------------- ----------------------------------

2) Check what storage engine mysql currently provides:

mysql> show engines; +------------+---------+------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +------------+---------+------------------------------------------------------------+--------------+------+------------+ | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO | | InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | +------------+---------+------------------------------------------------------------+--------------+------+------------+ 5 rows in set (0.00 sec)

3) Check the current default storage engine of mysql:

mysql> show variables like '%storage_engine%'; +----------------+--------+ | Variable_name | Value | +----------------+--------+ | storage_engine | MyISAM | +----------------+--------+ 1 row in set (0.00 sec)

4) Check what engine a certain table uses (the parameter after the engine parameter in the displayed results indicates the storage engine currently used by the table):

mysql> show create table table name;

mysql> show create table wx_share_log; +--------------+----------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +--------------+------------------------------------------------------------------------------------------------------------------------------------+ | wx_share_log | CREATE TABLE `wx_share_log` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '微信分享日志自增ID', `reference_id` int(11) NOT NULL COMMENT '推荐的经纪人id', `create_time` datetime NOT NULL COMMENT '创建时间', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 | +--------------+--------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)

5) How to import the MyISAM library into INNODB engine format:

In the backed up xxx.sql file, replace all ENGINE=MyISAM with ENGINE=INNODB

Just import it again.

6) Command to convert table:

mysql> alter table table name engine=innodb;

As you can see above, the storage engine used by mysql on this machine is the default MyISAN. Due to business needs, the storage engine must be changed to Innodb first.

The operation record is as follows:

1) Close mysql insafe mode

[root@dev mysql5.1.57]# mysqladmin -uroot -p shutdown Enter password: [root@dev mysql5.1.57]# ps -ef|grep mysql

2) Back up my.cnf

[root@dev mysql5.1.57]# cp my.cnf my.cnf.old

3) Modify my.cnfConfiguration file

[root@dev mysql5.1.57]# vim my.cnf ..... [mysqld] //在这个配置区域添加下面一行,指定存储引擎为innodb default-storage-engine = InnoDB

4)Delete ib_login the/mysql/data directory file0,ib_logfile1. Delete or cut elsewhere.

[root@dev var]# mv ib_logfile0 ib_logfile1 /tmp/back/

5) Start mysql, log in to mysql to verify whether the storage engine has been switched

[root@dev var]# /Data/app/mysql5.1.57/bin/mysqld_safe --defaults-file=/Data/app/mysql5.1.57/my.cnf &
mysql> show variables like '%storage_engine%'; +----------------+--------+ | Variable_name | Value | +----------------+--------+ | storage_engine | InnoDB | +----------------+--------+ 1 row in set (0.00 sec)

The above is the detailed content of Mysql replaces MyISAM storage engine with Innodb operation record sample code sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn