第一步:备份mysql数据库[root@server~]#mysqldump--all-databases--userroot--password--master-databackupdatabase.sqlEnterpassword:Warning:Skippingthedataoftablemysql.event.
第一步:备份mysql数据库
[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.
此命令将备份所有的数据库,并将其保存在当前目录中。
第二步:停止mysql服务:
[root@server ~]# service mysqld stop Stopping mysqld:
[ OK ]
[root@server ~]# chkconfig mysqld off
第三步:卸载mysql:
[root@server ~]# yum remove mysql* mysql-server mysql-devel mysql-libs
上面的命令将你当前MySQL的配置文件/etc/my.cnf文件到/etc/my.cnf.rpmsave进行备份。
第四步:安装REMI存储库,以解决MySQL的兼容性问题
你可能会得到在安装MariaDB的依赖关系错误。因此,让我们添加REMI存储库来解决依赖性问题。感谢AskMonty知识库帮我解决依赖关系问题。
[root@server ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
现在安装compat-mysql55包:
[root@server ~]# yum --enablerepo=remi-test --disablerepo=remi install compat-mysql55
第五步:安装Mariadb:
创建一个库文件为MariaDB的,并添加以下几行:
对于32位系统:
[root@server ~]# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 5.5 CentOS repository list - created
# 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
对于64为系统:
[root@server ~]# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 5.5 CentOS repository list
# 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
保存并退出运行
#yum update
下载开始安装Mariadb:
[root@server ~]# yum install MariaDB-devel MariaDB-client MariaDB-server -y
第六步:启动Mariadb服务
[root@server ~]# service mysql start
Starting MySQL...... SUCCESS!
[root@server ~]# chkconfig mysql on
第七步:设置Mysql root管理员密码:
[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.
Sample outputs
[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)]>
第八步:恢复/etc/my.cnf配置:
拷贝:/etc/my.cnf.rpmsave到/etc/my.cnf
[root@server ~]# cp /etc/my.cnf.rpmsave /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
第九步:导入数据库:
现在导入数据库备份
[root@server ~]# mysql -u root -p < backupdatabase.sql
Enter password:
第十步:重启Mariadb服务:
[root@server ~]# service mysql restart
Shutting down MySQL..
SUCCESS! Starting
MySQL...... SUCCESS!
就是这样。登录到MySQL服务器,并检查是否有旧的数据库和表。
输出类似如下:
[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)
检查数据库服务器状态:
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
-------------
检查表:
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)
如果你能看到上面显示的输出,那你就大功告成了。你已经成功升级从MySQL到MariaDB的。