{"id":20633,"date":"2020-11-30T04:23:10","date_gmt":"2020-11-29T20:23:10","guid":{"rendered":"https:\/\/web.mwwsb.com.my\/pjci\/?post_type=kb&p=20633"},"modified":"2023-01-18T10:58:08","modified_gmt":"2023-01-18T02:58:08","slug":"working-with-mysql-database-engines","status":"publish","type":"kb","link":"https:\/\/www.casbay.com\/guide\/kb\/working-with-mysql-database-engines","title":{"rendered":"Working with MySQL database engines"},"content":{"rendered":"\t\t
Database engines provide underlying functionality for MySQL to work with and process data.<\/p>
There are two most common and popular MySQL database engines: MyISAM<\/strong> and InnoDB<\/strong>. MyISAM<\/strong> is the default engine for MySQL (versions earlier than 5.5.5). It functions well in most scenarios and it is depending on your needs. There are some situations where another database engine, such as InnoDB<\/strong>, may be the better choice. For example, one of the differences between them is InnoDB supports transactions, whereas MyISAM does not. Besides, InnoDB provides support for foreign keys, whereas MyISAM does not.<\/p> Furthermore, you can complete control over how and when MySQL uses the various database engines when you have root access to your server. You can also change the default database engine, change the database engine of a specific table, and more.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t Firstly, type the following command at the mysql<\/strong>> prompt:<\/p> SHOW ENGINES; You can change the default database engine for your MySQL installation. After you do this, all new tables that you create will use the new database engine (unless you explicitly set the engine during table creation).<\/p> To change the default database engine, follow these steps:<\/p> If you are enabling the InnoDB database engine, depending on your Linux distribution you may have to disable the following line in the\u00a0my.cnf<\/em>\u00a0file:<\/p> To do this, just add a pound sign (#<\/strong>) to the beginning of the line, as follows:<\/p> To determine which engine a database table is currently using, type the following command at the\u00a0mysql><\/strong> prompt. Replace the\u00a0database<\/em>\u00a0with the name of the database that you want to check:<\/p> This command displays a list of every table in the database, along with the engine each table is using.<\/p><\/div>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t You can change the database engine for a table that already exists. For example, the following SQL statement shows how to modify a table named\u00a0myTable<\/em>\u00a0to use the InnoDB engine:<\/p> When you create a table in a database, you can explicitly set its database engine (otherwise, MySQL uses the default database engine during table creation). For example, the following SQL statement shows how to create a table named\u00a0myTable<\/em>\u00a0that uses the MyISAM database engine:<\/p> Similarly, to create a table that uses the InnoDB database engine, you could use the following SQL statement:<\/p>Determining The Default Database Engine\n<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
A list of supported engines appears, along with a brief description and the supported features for each engine. The default database engine is marked DEFAULT<\/strong> in the “Support” column.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\tChanging The Default Database Engine<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
default-storage-engine=ENGINE<\/em><\/pre>
skip-innodb<\/pre>
#skip-innodb<\/pre>
service mysqld restart<\/pre><\/li>
service mysql restart<\/pre><\/li><\/ul><\/li>
Determining A Table's Current Database Engine<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'database<\/em>';<\/pre>
Changing A Table's Database Engine<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
ALTER TABLE myTable ENGINE = InnoDB;<\/pre><\/div>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
Creating A New Table With A Specific Database Engine<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
CREATE TABLE myTable (\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id INT NOT NULL AUTO_INCREMENT,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PRIMARY KEY (id),\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 data VARCHAR(20) NOT NULL\n) ENGINE MyISAM;<\/pre>
CREATE TABLE myTable (\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id INT NOT NULL AUTO_INCREMENT,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PRIMARY KEY (id),\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 data VARCHAR(20) NOT NULL\n) ENGINE InnoDB;<\/pre><\/div>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t