
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to alter the database engine of a MySQL database table?
First, determine the type of MySQL database i.e. whether its engine is InnoDB or MyISAM. To achieve this, use engine column from the information_schema.columns.tables.
The syntax is as follows.
SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ’yourDatabaseName’ AND TABLE_NAME = ’yourTableName’;
Here, I have a table with the name ‘StudentInformations’ −
mysql> create table StudentInformations -> ( -> StudentId int not null auto_increment, -> StudentFirstName varchar(20), -> StudentLastName varchar(20), -> Primary Key(StudentId) -> ); Query OK, 0 rows affected (0.57 sec)
Now you can know the table is using InnoDB or MyISAM using the implementation of above syntax. Our database is ‘test’.
The query is as follows for the same −
mysql> select engine from information_schema.tables -> where table_schema = 'test' -> and table_name = 'StudentInformations';
The following is the output −
+--------+ | ENGINE | +--------+ | InnoDB | +--------+ 1 row in set (0.05 sec)
Change the engine of 'StudentInformations' table using alter command. The syntax is as follows to change the engine of any table.
ALTER TABLE yourTableName ENGINE = ‘yourEngineName’;
Let us now change the engine InnoDB to MyISAM. The query is as follows −
mysql> alter table StudentInformations ENGINE = 'MyISAM'; Query OK, 6 rows affected (1.84 sec) Records − 6 Duplicates − 0 Warnings − 0
The result displayed above shows 6 rows are affected because there are 6 rows in the table.
To check whether the table is converted from InnoDB to MyISAM or not, the following is the query −
mysql> select engine from information_schema.tables -> where table_schema = 'test' -> and table_name = 'StudentInformations';
Here is the output displaying the engine have been updated successfully −
+--------+ | ENGINE | +--------+ | MyISAM | +--------+ 1 row in set (0.00 sec)
- Related Articles
- How to take backup of a single table in a MySQL database?
- How to retrieve table names from a database in MySQL?
- How to check table status of the tables in a particular MySQL database?
- How to display the Engine of a MySQL table?
- How to normalize a Database Table
- How to copy a table from one MySQL database to another?
- How to check an empty table already in a MySQL database?
- How do I show the schema of a table in a MySQL database?
- Apply MySQL query to each table in a database?
- How to know the exact number of table and columns in a MySQL database?
- Select some data from a database table and insert into another table in the same database with MySQL
- Check how many rows are in a MySQL database table?
- How can we create a table from an existing MySQL table in the database?
- How can we change the default MySQL database to the given database?
- How to create a MySQL table with InnoDB engine table?
