大家好!这是一篇介绍如何在服务器或个人电脑上从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 的下载地址:请点这里
本文永久更新链接地址:

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
