Linux 上从 MySQL 迁移到 MariaDB 的简单步骤
大家好!这是一篇介绍如何在服务器或个人电脑上从MySQL迁移到MariaDB的教程。也许你会问为什么我们要将数据库管理从MySQL迁移到M
大家好!这是一篇介绍如何在服务器或个人电脑上从MySQL迁移到MariaDB的教程。也许你会问为什么我们要将数据库管理从MySQL迁移到MariaDB。往下看我们告诉你为什么这样做。
为什么要用MariaDB来代替MySQL
MariaDB是MySQL社区开发的分支,也是一个增强型的替代品。它由MySQL前开发者们带头组织的基金会开发,使用起来和MySQL完全一样。自从Oracle买下了MySQL,它就不再自由开源了,但是 MariaDB仍然自由开源。一些如谷歌、维基、LinkedIn、Mozilla等的顶级的网站已经迁移到MariaDB了。它的优势在哪里:
现在,让我们迁移到MariaDB吧!
让我们创建一个叫linoxidedb的用于测试的示例数据库。
使用以下命令用root账户登陆MySQL:
输入mysql 的 root 用户密码后,你将进入mysql的命令行
创建测试数据库:
在mysql命令行输入以下命令以创建测试数据库。
查看可用的数据库,输入以下命令:
如你所见,算上刚刚新建的linoxidedb我们一共有5个数据库。
现在,我们就将刚创建的数据库从MySQL迁移到MariaDB。
注:使用CentOS这类基于Fedora的linux发行版没有必要参考这篇教程,因为它们在安装MariaDB时会自动代替MySQL,无需备份现有的数据库,你只需要更新mysql就可以得到mariadb。
1. 备份现有的数据库
我们第一个重要的步骤就是备份现有的数据库。我们在终端(不是MySQL命令行)里输入如下命令来完成备份。
哇哦!我们遇到了点麻烦。别担心我们可以搞定。
mysqldump error
为了修复这个错误,我们需要对my.cnf文件做一些小改动。
编辑my.cnf文件:
在[mysqld]部分添加如下参数。
log-bin=mysql-bin
好了,在保存并关闭文件后,我们需要重启一下mysql服务。运行以下命令重启:
现在,重新运行mysqldump命令来备份所有的数据库。
dumping databases
上面的命令将会备份所有的数据库,把它们存储在当前目录下的backupdatabase.sql文件中。
2. 卸载MySQL
首先,我们得把my.cnf文件挪到安全的地方去。
注:在你卸载MySQL包的时候不会自动删除my.cnf文件,我们这样做只是以防万一。在MariaDB安装时,它会询问我们是保持现存的my.cnf文件,还是使用包中自带的版本(即新my.cnf文件)。
在shell或终端中输入如下命令来备份my.cnf文件:
运行命令来终止mysql服务:
然后移除mysql包:
3. 安装MariaDB
这是在Ubuntu系统中安装MariaDB的命令:
键值导入并且添加完仓库后,你就可以用以下命令安装MariaDB了:
我们应该还没忘记在MariaDB安装时,,它会问你是使用现有的my.cnf文件,还是包中自带的版本。你可以使用以前的my.cnf也可以用包中自带的。即使你想直接使用新的my.cnf文件,你依然可以晚点时候将以前的备份内容还原进去(别忘了我们已经将它复制到安全的地方了)。所以,我们直接选择了默认的选项“N”。如果需要安装其他版本,请参考。
4. 恢复配置文件
想要将my.cnf.bak中的内容恢复到my.cnf,在终端中输入以下命令。由于my.cnf.bak文件在当前目录下,所以我们只要简单的执行以下命令即可:
5. 导入数据库
最后,让我们把我们之前创建的数据库导入吧!运行一下命令即可完成导入。
就这样,我们已成功将之前的数据库导入了进来。
来,让我们登录一下mysql命令行,检查一下数据库是否真的已经导入了:
为了检查数据库是否被迁移到MariaDB,请在MariaDB命令行中输入“show databases;”不用输入(“”),如下:
如你所见,linoxidedb及所有的数据库都已经成功的被迁移了。
总结
最后,我们已经成功地从MySQL迁移到了MariaDB数据库管理系统。MariaDB比MySQL好,虽然在性能方面MySQL还是比它更快,但是MariaDB的优点在于它额外的特性与支持的许可证。这能够确保它自由开源(FOSS),并永久自由开源,相比之下MySQL还有许多额外的插件,有些不能自由使用代码、有些没有公开的开发进程、有些在不久的将来会变的不再自由开源。如果你有任何的问题、评论、反馈给我们,不要犹豫直接在评论区留下你的看法。谢谢观看本教程,希望你能喜欢MariaDB。
在 CentOS/RHEL/Scientific Linux 6 下安装 LAMP (Apache with MariaDB and PHP)
MariaDB Proxy读写分离的实现
Linux下编译安装配置MariaDB数据库的方法
CentOS系统使用yum安装MariaDB数据库
安装MariaDB与MySQL并存
Ubuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10
[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB
MariaDB 的详细介绍:请点这里
MariaDB 的下载地址:请点这里
本文永久更新链接地址:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
