How to batch convert the storage engine of MySQL database tables

Source: Internet
Author: User
Tags perl script

Mysql_convert_table_format ToolYesStorage engine for batch conversion of MYSQL database tablesFor RPM installation, it is generally in/usr/bin or/usr/sbin. This article describes how to use mysql_convert_table_format to convert the storage engine of MySQL database tablesMYISAMEngine method. Next let's take a look at this part.

First, execute the following code:

 
 
  1. [root@test ~]# mysql_convert_table_format  
  2.  
  3. /usr/sbin/mysql_convert_table_format version 1.1  
  4.  
  5. Conversion of a MySQL tables to other table types. 

Converts a MYSQL table to another table type, such as INNODB and MEMORY.

Usage:/usr/sbin/mysql_convert_table_format database [tables].

Usage:/usr/sbin/mysql_convert_table_format Database Name and table name, that is, you can specify the full database or full table separately, similar to mysqldump.

If no tables has been specifed, all tables in the database will be converted.

If no table is specified, all tables in the database will be converted.

 
 
  1. The following options are available:  
  2.  
  3. --force  
  4.  
  5. Continue even if there is some error. 

If an error occurs, force the conversion.

 
 
  1. --help or --Information  
  2.  
  3. Shows this help 

View help.

 
 
  1. --host='host name' (Default localhost)  
  2.  
  3. Host name where the database server is located. 

The converted host name. The default host name is localhost ).

 
 
  1. --password='password' 
  2.  
  3. Password for the current user. 

The password of the user currently being converted.

 
 
  1. --port=port  
  2.  
  3. TCP/IP port to connect to if host is not "localhost". 

If the connection is not based on localhost, specify the port.

 
 
  1. --socket='/path/to/socket' 
  2.  
  3. Socket to connect with. 

The location where the SOCKET file exists. SOCKET is used for inter-process communication ).

 
 
  1. --ENGINE='table-type' 
  2.  
  3. Converts tables to the given table type (Default: myisam)  
  4.  
  5. MySQL 3.23 supports at least the BDB, ISAM and MYISAM types. 

The storage engine is MYISAM by default. Note that during testing, you need to modify this PERL script. If you convert the database to INNODB, write MYISAM as INNODB in the script.

 
 
  1. --user='user_name' 
  2.  
  3. User name to log into the SQL server. 

The username of the connection.

 
 
  1. --verbose  
  2.  
  3. This is a test specific option that is only used when debugging a test.  
  4.  
  5. Print more information about what is going on.  
  6.  
  7. --version  
  8.  
  9. Shows the version of this program. 

View the version information of the tool.

Usage: I use a local machine for testing, OS: RHEL5.2 MYSQL: 5.1.30

Mysql_convert_table_format mo -- user = 'root' -- password = 'mysql' -- force -- socket = '/tmp/mysql. sock'

Converts all tables in the database mo To The MYISAM engine.

View the data file directory.

 
 
  1. [Root @ test ~] # Ll/opt/mysql-data/mo/
  2.  
  3. Total 960
  4.  
  5. -Rw ---- 1 mysql 12914 03-02 action_log.frm
  6.  
  7. -Rw ---- 1 mysql 8900 03-02 alarm_log.frm
  8.  
  9. -Rw ---- 1 mysql 8898 03-02 check_data.frm
  10.  
  11. -Rw ---- 1 mysql 8836 03-02 check_data_log.frm
  12.  
  13. -Rw ---- 1 mysql 1708 03-02 check_data_log.par
  14.  
  15. -Rw ---- 1 mysql 8898 03-02 check_data_tmp.frm
  16.  
  17. -Rw ---- 1 mysql 9096 03-02 checkpoint. frm
  18.  
  19. ...........................................

Only the structure file of the table is used to check whether the tablespace has grown.

 
 
  1. [root@test ~]# ll -lh /opt/mysql-data/ib*  
  2.  
  3. -rw-rw---- 1 mysql mysql 34M 03-02 23:18 /opt/mysql-data/ibdata1  
  4.  
  5. -rw-rw---- 1 mysql mysql 5.0M 03-02 23:18 /opt/mysql-data/ib_logfile0  
  6.  
  7. -rw-rw---- 1 mysql mysql 5.0M 12-22 20:19 /opt/mysql-data/ib_logfile1 

By default, INNODB is not used for 10 M, but now I have changed to 30 M.

Modify Tool

Change MYISAM to INNODB

Vi/usr/local/mysql/bin/mysql_convert_table_format

Change row 26th $ opt_type = "innodb" to $ opt_type = "myisam"

Convert databases with tools

 
 
  1. [root@test ~]# mysql_convert_table_format mo --user='root' --password='mysql' --socket='/tmp/mysql.sock' 
  2.  
  3. [root@test ~]# 

After successful completion, let's look at the data file:

 
 
  1. Total 2568
  2.  
  3. -Rw ---- 1 mysql 12914 03-02 action_log.frm
  4.  
  5. -Rw ---- 1 mysql 0 03-02 23:18 action_log.MYD
  6.  
  7. -Rw ---- 1 mysql 1024 03-02 action_log.MYI
  8.  
  9. -Rw ---- 1 mysql 8900 03-02 alarm_log.frm
  10.  
  11. -Rw ---- 1 mysql 0 03-02 alarm_log.MYD
  12.  
  13. -Rw ---- 1 mysql 1024 03-02 alarm_log.MYI
  14.  
  15. -Rw ---- 1 mysql 8898 03-02 check_data.frm
  16.  
  17. -Rw ---- 1 mysql 8836 03-02 check_data_log.frm
  18.  
  19. -Rw ---- 1 mysql 1708 03-02 check_data_log.par
  20.  
  21. -Rw ---- 1 mysql 0 03-02 check_data_log # P # define MYD
  22.  
  23. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # define myi
  24.  
  25. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p100.MYD
  26.  
  27. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p100.MYI
  28.  
  29. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p101.MYD
  30.  
  31. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p101.MYI
  32.  
  33. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p102.MYD
  34.  
  35. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p102.MYI
  36.  
  37. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p103.MYD
  38.  
  39. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p103.MYI
  40.  
  41. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p104.MYD
  42.  
  43. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p104.MYI
  44.  
  45. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p105.MYD
  46.  
  47. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p105.MYI
  48.  
  49. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p106.MYD
  50.  
  51. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p106.MYI
  52.  
  53. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p107.MYD
  54.  
  55. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p107.MYI
  56.  
  57. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p108.MYD
  58.  
  59. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p108.MYI
  60.  
  61. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p109.MYD
  62.  
  63. -Rw ---- 1 mysql 1024 03-02 check_data_log # P # p109.MYI
  64.  
  65. -Rw ---- 1 mysql 0 03-02 check_data_log # P # p10.MYD

The MYISAM engine has been successfully converted.

This section describes how to use the mysql_convert_table_format tool to batch convert the storage engine of MySQL database tables. We hope this introduction will help you gain some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.