I have a few hundred systems running running on a MariaDB 10.1.x. On these systems there is a master database which, for various legacy reasons, has to have MyISAM tables. I wish to produce slaves for these masters which have InnoDB versions of all the master MyISAM tables. For operational reasons, I would prefer not to have to perform various ALTER TABLE
operations on the slaves.
I was thinking (possibly simplistically) of taking the MySQLdump file from the master required as part of the initial slave setup, and then using some sort of script simply to alter its CREATE TABLE
commands to specify a table type of InnoDB rather than MyISAM.
Is this a sensible approach, and has anyone else tried it? Is there a better approach which would get me a slave which uses InnoDB without having to do loads of ALTER TABLE
s.
I am keen for this to be something which can be automated/script based, as we have literally hundreds of these systems in the field and so a manual upgrade process would be labour intensive and very error prone.
As an aside, I note that MySQL/MariaDB itself uses many MyISAM tables internally e.g. the mysql.user
table. Do they use MyISAM for any particular reason, or could these tables also safely be converted to InnoDB. Or am I better ensuring that any script I use to do the conversion avoids the tables in the mysql
database altogether?
Best Answer
I have created scripts where I flip the storage engine from MyISAM to InnoDB as follows:
If you want to see if this really works, just dump the schema as follows:
With reference to the mysql schema, please don't touch it. Why ???
In MySQL 5.5, all tables in the mysql schema were MyISAM.
In MySQL 5.6, that began to change
Here are the non-MyISAM tables for MySQL 5.6:
The two CSV tables are the slow log and error log, should your change log_output to FILE. The 5 InnoDB tables were introduced to support crash-safe replication (See Documentation on this).
It does not stop there. MySQL 5.7 introduced more InnoDB tables.
Here are the non-MyISAM tables for MySQL 5.7:
Please note that there are still 10 MyISAM in MySQL 5.7. Here they are:
Why are there 10 tables still in MyISAM ?
user
,db
,procs_priv
,proxies_priv
,tables_priv
, andcolumns_priv
are tables that store user grants.func
contains stored functionsproc
contains stored proceduresevent
contains schedules for executing eventsndb_binlog_index
contains info needed for the NDB storage engine (MySQL Cluster)These 10 tables are rarely used. Their contents are loaded into RAM on startup and then referenced from RAM. There is no need for them to be InnoDB because they are system-level tables that should not be changed via transaction.
Look at the potential problems that could occur if these 10 tables were InnoDB:
user
table crashes and gets corruptedThese and other problems can result and you would not even know it until mysqld restarts and nobody can log in, execute a stored procedure, or schedule a cron'd event.
Therefore, with good reason, these 10 tables were left as MyISAM. Again, please don't change the storage engine of anything in the
mysql
schema.