How to change MySQL default storage engine in CentOS 6.7

To change MySQL default storage engine in CentOS 6.7

A storage engine is a software module used by a database management system in order to create, read, and update data in a database. There are two types of storage engines in MySQLsuch as transactional and non-transactional. The default storage engine for MySQL prior to version 5.5 was MyISAM.

List of storage engines
MySQL supported storage engines:

  • InnoDB
  • MyISAM
  • Memory
  • CSV
  • Merge
  • Archive
  • Federated
  • Blackhole

InnoDB is the most widely used storage engine which has complete transaction support. It is an ACID compliant storage engine that supports row-level locking, crash recovery and multi-version concurrency control. It is to be noted that it provides foreign key referential integrity constraint, a feature that none of its competetors could boast of! Oracle recommends using InnoDB for tables except for specialized use cases.

MyISAM is the original storage engine which was considered to be a fast storage engine. Although it does not support transactions, it provides table-level locking. It is used mostly in Web and data warehousing.

To change MySQL default storage engine

Before initiating the procedure to change MySQL default storage, check MySQL package by running the following command.

[root@localhost ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64

Here, MySQL is not installed so use the following command to install MySQL

.

[root@localhost ~]# yum install mysql-server
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos-hcm.viettelidc.com.vn
 * updates: centos-hcm.viettelidc.com.vn
Resolving Dependencies
-->  Running transaction check
--->  Package mysql-server.x86_64 0:5.1.73-8.el6_8 will be installed
-->  Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                Arch                             Version                                     Repository                         Size
=============================================================================================================================================================
Installing:
 mysql-server                           x86_64                           5.1.73-8.el6_8                              updates                           8.6 M

Transaction Summary
=============================================================================================================================================================
Install       1 Package(s)

Total download size: 8.6 M
Installed size: 25 M
Is this ok [y/N]: y
Downloading Packages:
http://centos-hcm.viettelidc.com.vn/6.8/updates/x86_64/Packages/mysql-server-5.1.73-8.el6_8.x86_64.rpm: [Errno 12] Timeout on http://centos-hcm.viettelidc.com.vn/6.8/updates/x86_64/Packages/mysql-server-5.1.73-8.el6_8.x86_64.rpm: (28, ' Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds' )
Trying other mirror.
mysql-server-5.1.73-8.el6_8.x86_64.rpm                                                                                                | 8.6 MB     00:22     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-server-5.1.73-8.el6_8.x86_64                                                                                                        1/1 
  Verifying  : mysql-server-5.1.73-8.el6_8.x86_64                                                                                                        1/1 

Installed:
  mysql-server.x86_64 0:5.1.73-8.el6_8                                                                                                                       

Complete!

Once MySQL is installed, start the MySQL

[root@localhost ~]# service mysqld start
Starting mysqld:                                           [  OK  ]  


Next configure the my sql with secure installations.

[root@localhost ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we' ll need the current
password for the root user.  If you' ve just installed MySQL, and
you haven' t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user ' root' @' localhost'  (using password: NO)
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer ' n' .

Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from ' localhost' .  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MySQL comes with a database named ' test'  that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can' t drop database ' test'   database doesn' t exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you' ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Open the MySQL and run “ show engines ” to view the storage engines.

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with   or g.
Your MySQL connection id is 11
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ' help '  or ' h'  for help. Type ' c'  to clear the current input statement.

mysql>  show engines 
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)

mysql>  exit 
Bye

Next open the my.cnf file and add the “ default-storage-engine = < storage engine name>

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
default-storage-engine = innodb 

Now, restart the MySQL service.

[root@localhost ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]


Again check the storage engine as a root user.

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with   or g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ' help '  or ' h'  for help. Type ' c'  to clear the current input statement.

mysql>  show engines 
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | YES     | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| InnoDB     | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)

mysql>  exit
Bye


Tag : CentOS MySQL
FAQ
Q
what command used to configure the my sql with secure installations?
A
configure the my sql with secure installations by below command
# mysql_secure_installation
Q
what are all the list of mysql supported engine?
A
the list of mysql supported engine are,
InnoDB
MyISAM
Memory
CSV
Merge
Archive
Federated
Blackhole
Q
what is the MySQL storage engine in CentOS?
A
A storage engine is a software module used by a database management system in order to create, read, and update data in a database. There are two types of storage engines in MySQLsuch as transactional and non-transactional. The default storage engine for MySQL prior to version 5.5 was MyISAM.
Q
How to check mysql package name using yum command?
A
Use "yum whatprovides mysql"
Q
Where to change the default storage engine?
A
At "/etc/my.cnf" location add the “default-storage-engine =