This article describes you how to upgrade MySQL to MariaDB in ten simple steps. We have already shown you How to Migrate from MySQL to MariaDB on FreeBSD. I assume that you already have installed MySQL latest version and it’s up and running now.
Step1 : Backup MySQL Databases
[root@server ~]# mysqldump --all-databases --user=root --password --master-data > backupdatabase.sql Enter password: -- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
This command will backup all databases and save them in the current directory.
Step 2: Stop MySQL service
[root@server ~]# service mysqld stop Stopping mysqld: [ OK ] [root@server ~]# chkconfig mysqld off
Step 3: Remove MySQL
Remove all MySQL packages now:
[root@server ~]# yum remove mysql* mysql-server mysql-devel mysql-libs
The above command will take the backup of your current MySQL config file /etc/my.cnf to /etc/my.cnf.rpmsave.
Step 4: Install REMI Repository to resolve MySQL Compatibility issue
You will probably get dependencies errors while installing MariaDB. So let us add REMI Repository to solve dependencies problems.
Thanks to AskMonty Knowledgebase to help me to solve the dependencies issues.
[root@server ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Install compat-mysql55 package now:
[root@server ~]# yum --enablerepo=remi-test --disablerepo=remi install compat-mysql55
Step 5: Install MariaDb
Create a repository file for MariaDB and add the following lines:
For 32bit systems:
[root@server ~]# vi /etc/yum.repos.d/mariadb.repo # MariaDB 5.5 CentOS repository list - created 2013-06-06 07:42 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/5.5/centos6-x86 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
For 64bit systems:
[root@server ~]# vi /etc/yum.repos.d/mariadb.repo
#MariaDB 5.5 CentOS repository list - created 2013-06-06 07:53 UTC
#http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/5.5/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
Save and exit the file and run yum update command:
[root@server ~]# yum update
Now start installing MariaDB:
[root@server ~]# yum install MariaDB-devel MariaDB-client MariaDB-server -y
Step 6: Start MariaDB service
[root@server ~]# service mysql start Starting MySQL...... SUCCESS! [root@server ~]# chkconfig mysql on
Step 7: Set MySQL root password
[root@server ~]# /usr/bin/mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, 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): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB 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 MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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, MariaDB 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 MariaDB installation should now be secure. Thanks for using MariaDB!
Step 8: Restore /etc/my.cnf config file
Now copy the contents of the file /etc/my.cnf.rpmsave to /etc/my.cnf file:
[root@server ~]# cp /etc/my.cnf.rpmsave /etc/my.cnf cp: overwrite `/etc/my.cnf'? y
Step 9: Import Database
Now import the database backup which we created back in Step 1:
[root@server ~]# mysql -u root -p < backupdatabase.sql Enter password:
Step 10: Restart MariaDB service
[root@server ~]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL...... SUCCESS!
That’s it. Login to the MySQL server and check for the old databases and tables.
[root@server ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.31-MariaDB-log MariaDB Server Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | unixmen | +--------------------+ 3 rows in set (0.01 sec)
Check the status of the of database server:
MariaDB [(none)]> status; -------------- mysql Ver 15.1 Distrib 5.5.31-MariaDB, for Linux (i686) using readline 5.1 Connection id: 3 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server: MariaDB Server version: 5.5.31-MariaDB-log MariaDB Server Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/lib/mysql/mysql.sock Uptime: 6 min 15 sec Threads: 1 Questions: 7 Slow queries: 0 Opens: 0 Flush tables: 2 Open tables: 8 Queries per second avg: 0.018 --------------
Verify the tables:
MariaDB [(none)]> use unixmen; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [unixmen]> show tables; +-------------------+ | Tables_in_unixmen | +-------------------+ | sample | +-------------------+ 1 row in set (0.01 sec)
If you seen the output like shown above, you’re done. You successfully upgraded from MySQL to MariaDB.