Converting MyISAM tables to InnoDB

From EPrints Documentation
Revision as of 15:54, 5 August 2019 by (talk | contribs) (Added script that can be used to convert database table engines)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Below is Bash script that will convert all tables to InnoDB if they are currently MyISAM. If tables are already InnoDB nothing will change and the script should complete quite quickly. If not you may find it takes several hours to run. It is advised that if you are running this on a live repository you do the following:

  1. Take the repository offline (i.e. either completely stop Apache and the EPrints indexer or get the former to load a splash screen saying the repository is down for maintenance).
  2. Take a backup of the database or if you are running the server as a virtual machine, a snapshot of the whole server.
  3. Run the script below direct from the console or in screen, in case you lose your network connection.

if [ -z $1 ]; then
  echo "Usage: $0 <DATABASE_NAME>"
  exit 1

read -p "Please enter the hostname of the server hosting this database [localhost]: " hostname
read -p "Please enter a username that has permission to alter tables [root]: " username
read -sp "Please enter the password for this user: " password

if [ -z "$hostname" ]; then
if [ -z "$username" ]; then
if [ ! -z $password ]; then
mysql_start="mysql -h $hostname -u $username $mysql_password $database"

for t in $(echo "show tables" | $mysql_start --batch --skip-column-names); do
    sql="ALTER TABLE \`$t\` ENGINE = InnoDB;"
    echo $sql
    time $mysql_start -e "$sql";