mirror of
https://github.com/LCTT/TranslateProject.git
synced 2026-09-01 04:27:55 +08:00
@@ -1,171 +0,0 @@
|
||||
Translating by martin.
|
||||
|
||||
Simple Steps Migration From MySQL To MariaDB On Linux
|
||||
================================================================================
|
||||
Hi all, this tutorial is all gonna be about how to migrate from MySQL to MariaDB on Linux Server or PC. So, you may ask why should we really migrate from MySQL to MariaDB for our database management. Here, below are the reasons why you should really need to migrate your database management system from MySQL to MariaDB.
|
||||
|
||||
### Why should I use MariaDB instead of MySQL? ###
|
||||
|
||||
MariaDB is an enhanced drop-in replacement and community-developed fork of the MySQL database system. It was developed by MariaDB foundation, and is being led by original developers of MySQL. Working with MariaDB is entirely same as MySQL. After Oracle bought MySQL, it is not free and open source anymore, but **MariaDB is still free and open source**. Top Websites like Google, Wikipedia, Linkedin, Mozilla and many more migrated to MariaDB. Its features are
|
||||
|
||||
- Backwards compatible with MySQL
|
||||
- Forever open source
|
||||
- Maintained by MySQL's creator
|
||||
- More cutting edge features
|
||||
- More storage engines
|
||||
- Large websites have switched
|
||||
|
||||
Now, lets migrate to MariaDB.
|
||||
|
||||
**For the testing purpose**, let us create a sample database called **linoxidedb** .
|
||||
|
||||
Log in to MySQL as root user using the following command:
|
||||
|
||||
$ mysql -u root -p
|
||||
|
||||
Enter the mysql root user password. You’ll be redirected to the **mysql prompt**.
|
||||
|
||||
**Create test databases:**
|
||||
|
||||
Enter the following commands from mysql prompt to create test databases.
|
||||
|
||||
mysql> create database linoxidedb;
|
||||
|
||||
To view the list of available databases, enter the following command:
|
||||
|
||||
mysql> show databases;
|
||||
|
||||

|
||||
|
||||
As see above, we have totally 5 databases including the newly created database linoxidedb .
|
||||
|
||||
mysql> quit
|
||||
|
||||
Now, we'll migrate the created databases from MySQL to MariaDB.
|
||||
|
||||
Note: This tutorial is not necessary for CentOS, fedora based distribution of Linux because MariaDB is automatically installed instead of MySQL which requires no need to backup the existing databases, you just need to update mysql which will give you mariadb.
|
||||
|
||||
### 1. Backup existing databases ###
|
||||
|
||||
Our first important step is to create a backup of existing databases. To do that, we'll enter the following command from the **Terminal (not from MySQL prompt)**.
|
||||
|
||||
$ mysqldump --all-databases --user=root --password --master-data > backupdatabase.sql
|
||||
|
||||
Oops! We encountered an error. No worries, it can be fixed.
|
||||
|
||||
$ mysqldump: Error: Binlogging on server not active
|
||||
|
||||

|
||||
mysqldump error
|
||||
|
||||
To fix this error, we have to do a small modification in **my.cnf** file.
|
||||
|
||||
Edit my.cnf file:
|
||||
|
||||
$ sudo nano /etc/mysql/my.cnf
|
||||
|
||||
Under [mysqld] section, add the following parameter.
|
||||
|
||||
**log-bin=mysql-bin**
|
||||
|
||||

|
||||
|
||||
Now, after done save and exit the file. Then, we'll need to restart mysql server. To do that please execute the below commands.
|
||||
|
||||
$ sudo /etc/init.d/mysql restart
|
||||
|
||||
Now, re-run the mysqldump command to backup all databases.
|
||||
|
||||
$ mysqldump --all-databases --user=root --password --master-data > backupdatabase.sql
|
||||
|
||||

|
||||
dumping databases
|
||||
|
||||
The above command will backup all databases, and stores them in **backupdatabase.sql** in the current directory.
|
||||
|
||||
### 2. Uninstalling MySQL ###
|
||||
|
||||
First of all, we'll want to **backup the my.cnf file to a safe location**.
|
||||
|
||||
**Note**: The my.cnf file will not be deleted when uninstalling MySQL packages. We do it for the precaution. During MariaDB installation, the installer will ask us to keep the existing my.cnf(old backup) file or to use the package containers version (i.e new one).
|
||||
|
||||
To backup the my.cnf file, please enter the following commands in a shell or terminal.
|
||||
|
||||
$ sudo cp /etc/mysql/my.cnf my.cnf.bak
|
||||
|
||||
To stop mysql service, enter the following command from your Terminal.
|
||||
|
||||
$ sudo /etc/init.d/mysql stop
|
||||
|
||||
Then, remove mysql packages.
|
||||
|
||||
$ sudo apt-get remove mysql-server mysql-client
|
||||
|
||||

|
||||
|
||||
### 3. Installing MariaDB ###
|
||||
|
||||
Here are the commands to run to install MariaDB on your Ubuntu system:
|
||||
|
||||
$ sudo apt-get install software-properties-common
|
||||
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
|
||||
# sudo add-apt-repository 'deb http://mirror.mephi.ru/mariadb/repo/5.5/ubuntu trusty main'
|
||||
|
||||

|
||||
|
||||
Once the key is imported and the repository added you can install MariaDB with:
|
||||
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install mariadb-server
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
We should remember that during MariaDB installation, the installer will ask you either to use the existing my.cnf(old backup) file, or use the package containers version (i.e new one). You can either use the old my.cnf file or the package containers version. If you want to use the new my.cnf version, you can restore the contents of older my.cnf (We already have copied this file to safe location before) later ie my.cnf.bak . So, I will go for default which is N, we'll press N then. For other versions, please refer the [MariaDB official repositories page][2].
|
||||
|
||||
### 4. Restoring Config File ###
|
||||
|
||||
To restore my.cnf from my.cnf.bak, enter the following command in Terminal. We have the old as my.cnf.bak file in our current directory, so we can simply copy the file using the following command:
|
||||
|
||||
$ sudo cp my.cnf.bak /etc/mysql/my.cnf
|
||||
|
||||
### 5. Importing Databases ###
|
||||
|
||||
Finally, lets import the old databases that we created before. To do that, we'll need to run the following command.
|
||||
|
||||
$ mysql -u root -p < backupdatabase.sql
|
||||
|
||||
That’s it. We have successfully imported the old databases.
|
||||
|
||||
Let us check if the databases are really imported. To do that, we'll wanna log in to mysql prompt using command:
|
||||
|
||||
$ mysql -u root -p
|
||||
|
||||

|
||||
|
||||
Now, to check whether the databases are migrated to MariaDB please run "**show databases**;" command inside the MarianDB prompt without quotes("") as
|
||||
|
||||
mariaDB> show databases;
|
||||
|
||||

|
||||
|
||||
As you see in the above result all old databases including our very linoxidedb has been successfully migrated.
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
Finally, we have successfully migrated our databases from MySQL to MariaDB Database Management System. MariaDB is far more better than MySQL. Though MySQL is still faster than MariaDB in performance but MariaDB is far more better because of its additional features and license. MariaDB is a Free and Open Source Software (FOSS) and will be FOSS forever but MySQL has many additional plugins, etc non-free and there is no proper public roadmap and won't be FOSS in future. If you have any questions, comments, feedback to us, please don't hesitate to write on the comment box below. Thank You ! And Enjoy MariaDB.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-how-to/migrate-mysql-mariadb-linux/
|
||||
|
||||
作者:[Arun Pyasi][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/arunp/
|
||||
[1]:https://mariadb.org/
|
||||
[2]:https://downloads.mariadb.org/mariadb/repositories/#mirror=mephi
|
||||
@@ -0,0 +1,169 @@
|
||||
Linux上从MySQL迁移到MariaDB的简单步骤
|
||||
================================================================================
|
||||
大家好!这是一篇介绍如何在服务器或个人电脑上从MySQL迁移到MariaDB的教程。也许你会问为什么我们要将数据库管理从MySQL迁移到MariaDB。往下看我们告诉你为什么这样做。
|
||||
|
||||
### 为什么要用MariaDB来代替MySQL ###
|
||||
|
||||
MariaDB是MySQL社区开发的分支,也是一个增强型的替代品。它由MySQL前开发者们带头组织的基金会开发,使用起来和MySQL完全一样。自从Oracle买下了MySQL,它就不再自由开源了,但是 **MariaDB仍然自由开源**。一些如谷歌、维基、LinkedIn、Mozilla等的顶级的网站已经迁移到MariaDB了。它的优势在哪里:
|
||||
|
||||
- 向后兼容MySQL
|
||||
- 永远开源
|
||||
- 由MySQL缔造者的维护
|
||||
- 更尖端的功能
|
||||
- 更多的存储引擎
|
||||
- 大型的网站已经转向MariaDB
|
||||
|
||||
现在,让我们迁移到MariaDB吧!
|
||||
|
||||
**以测试为目的**让我们创建一个叫**linoxidedb**的示例数据库。
|
||||
|
||||
使用以下命令用root账户登陆MySQL:
|
||||
|
||||
$ mysql -u root -p
|
||||
|
||||
输入mysql root用户的密码后,你将进入**mysql的命令行**
|
||||
|
||||
**创建测试数据库:**
|
||||
|
||||
在mysql命令行输入以下命令以创建测试数据库。
|
||||
|
||||
mysql> create database linoxidedb;
|
||||
|
||||
查看可用的数据库,输入以下命令:
|
||||
|
||||
mysql> show databases;
|
||||
|
||||

|
||||
|
||||
如你所见,算上刚刚新建的linoxidedb我们一共有5个数据库。
|
||||
|
||||
mysql> quit
|
||||
|
||||
现在,我们就将刚创建的数据库从MySQL迁移到MariaDB。
|
||||
|
||||
注:使用CentOS这类基于fedora的linux发行版没有必要参考这篇教程,因为它们在安装MariaDB时会自动代替MySQL,无需备份现有的数据库,你只需要更新mysql就可以得到mariadb。
|
||||
|
||||
### 1. 备份现有的数据库 ###
|
||||
|
||||
我们第一个重要的步骤就是备份现有的数据库。我们在**终端(不是MySQL命令行)**里输入如下命令来完成备份。
|
||||
|
||||
$ mysqldump --all-databases --user=root --password --master-data > backupdatabase.sql
|
||||
|
||||
哇哦!我们遇到了点麻烦。别担心我们可以搞定。
|
||||
|
||||
$ mysqldump: Error: Binlogging on server not active
|
||||
|
||||

|
||||
mysqldump error
|
||||
|
||||
为了修复这个错误,我们需要对**my.cnf**文件做一些小改动。
|
||||
|
||||
编辑my.cnf文件:
|
||||
|
||||
$ sudo nano /etc/mysql/my.cnf
|
||||
|
||||
在[mysqld]部分添加如下参数。
|
||||
|
||||
**log-bin=mysql-bin**
|
||||
|
||||

|
||||
|
||||
好了在保存并关闭文件后,我们需要重启一下mysql服务。运行以下命令重启:
|
||||
|
||||
$ sudo /etc/init.d/mysql restart
|
||||
|
||||
现在,重新运行mysqldump命令来备份所有的数据库。
|
||||
|
||||
$ mysqldump --all-databases --user=root --password --master-data > backupdatabase.sql
|
||||
|
||||

|
||||
dumping databases
|
||||
|
||||
上面的命令将会备份所有的数据库,把它们存储在当前目录下的**backupdatabase.sql**文件中。
|
||||
|
||||
### 2. 卸载MySQL ###
|
||||
|
||||
首先,我们得把**my.cnt文件挪到安全的地方去**。
|
||||
|
||||
**注**:my.cnf文件将不会在你卸载MySQL包的时候被删除,我们这样做只是以防万一。在MariaDB安装时,它会询问我们是保持现存的my.cnf文件,还是使用包中自带的版本(即新my.cnf文件)。
|
||||
|
||||
在shell或终端中输入如下命令来备份my.cnt文件:
|
||||
|
||||
$ sudo cp /etc/mysql/my.cnf my.cnf.bak
|
||||
|
||||
运行命令来终止mysql服务:
|
||||
|
||||
$ sudo /etc/init.d/mysql stop
|
||||
|
||||
然后移除mysql包:
|
||||
|
||||
$ sudo apt-get remove mysql-server mysql-client
|
||||
|
||||

|
||||
|
||||
### 3. 安装MariaDB ###
|
||||
|
||||
这是在Ubuntu系统中安装MariaDB的命令:
|
||||
|
||||
$ sudo apt-get install software-properties-common
|
||||
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
|
||||
# sudo add-apt-repository 'deb http://mirror.mephi.ru/mariadb/repo/5.5/ubuntu trusty main'
|
||||
|
||||

|
||||
|
||||
键值导入并且添加完仓库后你就可以用以下命令安装MariaDB了:
|
||||
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install mariadb-server
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
我们应该还没忘记在MariaDB安装时,它会问你是使用现有的my.cnf文件,还是包中自带的版本。你可以使用以前的my.cnf也可以用包中自带的。即使你想直接使用新的my.cnf文件,你依然可以晚点将以前的备份内容还原进去(别忘了我们已经将它复制到安全的地方那个去了)。所以,我们直接选择了默认的选项“N”。如果需要安装其他版本,请参考[MariaDB官方仓库][2]。
|
||||
|
||||
### 4. 恢复配置文件 ###
|
||||
|
||||
想要将my.cnf.bak中的内容恢复到my.cnf,在终端中输入以下命令。由于my.cnf.bak文件在当前目录下,所以我们只要简单的执行以下命令即可:
|
||||
|
||||
$ sudo cp my.cnf.bak /etc/mysql/my.cnf
|
||||
|
||||
### 5. 导入数据库 ###
|
||||
|
||||
最后,让我们把我们之前创建的数据库导入吧!运行一下命令即可完成导入。
|
||||
|
||||
$ mysql -u root -p < backupdatabase.sql
|
||||
|
||||
就这样,我们已成功将之前的数据库导入了进来。
|
||||
|
||||
来,让我们登陆一下mysql命令行,检查一下数据库是否真的已经导入了:
|
||||
|
||||
$ mysql -u root -p
|
||||
|
||||

|
||||
|
||||
为了检查数据库是否被迁移到MariaDB,请在MariaDB命令行中输入“**show databases**;”不用输入(“”),如下:
|
||||
|
||||
mariaDB> show databases;
|
||||
|
||||

|
||||
|
||||
如你所见,linoxidedb及所有的数据库都已经成功的被迁移了。
|
||||
|
||||
### 总结 ###
|
||||
|
||||
最后,我们已经成功地从MySQL迁移到了MariaDB数据库管理系统。MariaDB比MySQL好,虽然在性能方面MySQL还是比它更快,但是MariaDB的优点在于它额外的特性与支持的许可证。这能够确保它自由开源(FOSS),并永久自由开源,相比之下MySQL还有许多额外的插件,有些不能自由使用代码、有些没有公开的开发进程、有些在不久的将来会变的不再自由开源。如果你有任何的问题、评论、反馈给我们,不要犹豫直接在评论区留下你的看法。谢谢观看本教程,希望那你能喜欢MariaDB。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-how-to/migrate-mysql-mariadb-linux/
|
||||
|
||||
作者:[Arun Pyasi][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/arunp/
|
||||
[1]:https://mariadb.org/
|
||||
[2]:https://downloads.mariadb.org/mariadb/repositories/#mirror=mephi
|
||||
Reference in New Issue
Block a user