Home > Database > Mysql Tutorial > How Can I Bulk Convert All MyISAM Tables to InnoDB in MySQL?

How Can I Bulk Convert All MyISAM Tables to InnoDB in MySQL?

Barbara Streisand
Release: 2025-01-04 03:16:39
Original
976 people have browsed it

How Can I Bulk Convert All MyISAM Tables to InnoDB in MySQL?

Bulk Conversion of MyISAM Tables to InnoDB: A Comprehensive Guide

Introduction

Modifying tables from MyISAM to InnoDB one at a time can be tedious. The following article provides a comprehensive solution to quickly convert all MyISAM tables in a database to InnoDB using SQL.

Detailed Solution

To achieve this bulk conversion, execute the following SQL statement:

SET @DATABASE_NAME = 'name_of_your_db';

SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements
FROM information_schema.tables AS tb
WHERE table_schema = @DATABASE_NAME
AND `ENGINE` = 'MyISAM'
AND `TABLE_TYPE` = 'BASE TABLE'
ORDER BY table_name DESC;
Copy after login

Make sure to replace name_of_your_db with the name of your database.

Implementation

After running the SQL statement above, the output will provide a list of SQL statements that convert each MyISAM table to InnoDB. Copy these statements into a new SQL query window and execute them. This will execute the conversion for all MyISAM tables in your database.

Benefits of InnoDB over MyISAM

InnoDB offers several advantages over MyISAM, including:

  • Improved data integrity through transactions and foreign key constraints
  • Increased write performance due to row-level locking
  • Better scalability and concurrency for high-load applications
  • Full-text search and foreign key support

The above is the detailed content of How Can I Bulk Convert All MyISAM Tables to InnoDB in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template