How to replace MySQL with MariaDB on CentOS 6

MySQL至MariaDB迁移指南
本文档详细介绍了如何从MySQL无缝迁移到高性能替代方案MariaDB的过程。包括卸载MySQL、安装MariaDB及其兼容组件,并解决可能遇到的兼容性问题。

        MariaDB is a high performance drop-in replacement for MySQL, developed by some of the original authors of the MySQL project. This how-to will walk you through uninstalling MySQL and then installing MariaDB from their repository using the YUM package manager.

Removing MySQL

WARNING: Make sure to back up any databases you would like to keep, before you remove MySQL. Otherwise they may be lost forever!

The first step is removing MySQL using YUM.


 
  1. yum remove mysql* 

(The * is a wildcard, and tells YUM to remove all packages starting with the string "mysql".)

In my case the list of packages that will be removed is:


 
  1. mysql 
  2. mysql-devel 
  3. mysql-libs 
  4. mysql-server 
  5. perl-DBD-MySQL 

(The last package is removed as a dependency.)

This will backup the old mysql.log from /var/log/mysqld.log to /var/log/mysqld.log.rpmsave, and your MySQL config my.cnf from /etc/my.cnf to /etc/my.cnf.rpmsave. You can restore the MySQL config file later (by simply renaming it back) if you would like to use it for MariaDB.

Comatibility with Remi PHP packages

This is important if you are installing PHP-FPM from the Remi repository (for an example following our how-to/tutorial). There is a compatibility issue that needs to be addressed before you proceed with installing MariaDB:

Install the following package from Remi test:


 
  1. yum --enablerepo=remi-test --disablerepo=remi install compat-mysql55 

A big thanks goes to malinens over at askmonty.org for pointing this out.

If you have made the mistake of installing MariaDB prior to discovering this issue, and getting an error similar to this upon starting PHP-FPM:


 
  1. NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: symbol mysql_client_errors, version libmysqlclient_18 not defined in file libmysqlclient.so.18 with link time reference in Unknown on line 0 

You need to remove all mysql related packages from your system first:


 
  1. yum remove mysql-server mysql-libs mysql-devel mysql* 

This will remove among others all the MariaDB packages, and php-mysql.

Next, install the compat-mysql55 package as instructed above - making sure to use the enable/disable repo commands to only get this particular package from the test repo.

Once that is done, proceed with re-installing MariaDB as per the instructions below, along with php-mysql (yum install php-mysql).

Installing MariaDB

First, let's add MariaDBs repository. Create the file /etc/yum.repos.d/MariaDB.repo by opening it in your favorite editor. We will use vim here, but nano might be easier if you are new to Linux (yum install nano, then nano -w filepath).


 
  1. vi /etc/yum.repos.d/MariaDB.repo 
  2. [mariadb] 
  3. name = MariaDB 
  4. baseurl = http://yum.mariadb.org/5.5/centos6-x86 
  5. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 
  6. gpgcheck=1 

You should note that the last part of the baseurl needs to match your CentOS version and arch. In my case this would need to be centos6-amd64, for a 64-bit install, but since x86 (32-bit) is more common I've left that in the example above.

Save the file and exit your editor. (In vim this is done by holding Shif and pressing : (colon), entering "wq" (without the quotes) for "write quit", and enter.) 

Moving on to installing the components using YUM:


 
  1. yum install MariaDB-server MariaDB-client 
  2. //This will install: 
  3. MariaDB-client 
  4. MariaDB-server 
  5. MariaDB-common 
  6. MariaDB-compat 

(The last two being dependencies.)

Now that it is installed, let's start the service:


 
  1. # service mysql start 
  2. Starting MySQL.. SUCCESS! 

Next, we secure the installation:


 
  1. # mysql_secure_installation 

This will run you through securing the installation, and you should read each step carefully. I recommend that you set an appropriate root password, remove anonymous users, disallow remote root login, and remove the test database and access. Reload the privilege tables if you do.

Note: If you had a MySQL server running before you started, and uninstalled the MySQL database prior to installing MariaDB, the old data files should still be there. In that case the mysql_secure_installation procedure will fail if you try to feed it a blank root password... providing you have previously secured your MySQL install. You can then either skip running the script, or you can re-run it by supplying the previously set root password from the MySQL install.

Next you will want to set MariaDB to start on boot:


 
  1. # chkconfig mysql on 
  2. And restart the MariaDB server: 
  3. # service mysql restart 
  4. Shutting down MySQL. SUCCESS! 
  5. Starting MySQL.. SUCCESS! 

Let's try to connect, shall we?


 
  1. # mysql -uroot -p    //Enter your database root password when promted. 
  2. Welcome to the MariaDB monitor.  Commands end with ; or \g. 
  3. Your MariaDB connection id is 2 
  4. Server version: 5.5.29-MariaDB MariaDB Server 
  5.  
  6. Copyright (c) 2000, 2012, Oracle, Monty Program Ab and others. 
  7.  
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  9.  
  10. MariaDB [(none)]> 

All done! Enjoy your new MariaDB server.

1.MariaDB

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值