1. Set the default storage engine for the entire database
Two application scenarios
Scenario 1: Set the persistent default storage engine of the database
Set the server storage engine in the startup configuration file
[mysqld]
default-storage-engine=<存储引擎名>
Example
1) The MySQL database version of my system is: 5.7.32.
Modify the file:, sudo vi mysqld.cnf
add default-storage-engine=MyISAM
. The file path of the 5.7.32 version is: /etc/mysql/mysql.conf.d
2) Restart MySQL after modification: sudo /etc/init.d/mysql restart
3) You can see that the database default storage engine has changed to the type we want to set
Scenario 2: Set the temporary default storage engine of the database
instruction:
SET default_storage_engine=<存储引擎名>
Example:
1) Query the original storage engine of the database
show engines;
2) Set the database temporary storage engine
SET default_storage_engine=MyISAM;
3) Query the database and set the new storage engine
show engines;
We can see that the default storage engine has become the target type we set. (Note: After the database is restarted, it will revert to the original default storage engine)
Two, set the storage engine of the specified table
1. Specify the storage engine of the table when creating the table
create table user_info (
id int not null auto_increment,
`name` varchar(20),
`title` varchar(20),
`money` int,
primary key(id)
) engine = InnoDB charset = utf8;
2. Modify the storage engine of an existing table
instruction:
ALTER TABLE <表名> ENGINE=<存储引擎名>;
Example:
1) Query the original storage engine of the user_info table
show create table user_info;
2) Modify the user_info table storage engine to MyISAM
ALTER TABLE user_info ENGINE=MyISAM;
3) Query the newly set storage engine of the user_info table
show create table user_info;