Table of Contents
Preparing the MySQL database and tables
Create a database and tables
Backup of MySQL database
Uninstall the MySQL package
Install MariaDB package
Import MySQL database
Home Database Mysql Tutorial How to migrate MySQL to MariaDB on Linux?

How to migrate MySQL to MariaDB on Linux?

Aug 31, 2023 am 09:13 AM

如何在 Linux 上将 MySQL 迁移到 MariaDB?

This article will help you migrate your database from MySQL to MariaDB because MySQL to MariaDB binary compatibility is very simple during the migration process.

After Oracle acquired MySQL, the community drove the results of such a movement and developed a new database called MariaDB. MariaDB is open source and compatible with MySQL. Most Linux distributions (RH, CentOS, Fedora) have started using MariaDB support as a drop-in replacement for MySQL.

If we want to migrate the database from MySQL to MariaDB, then this article will be helpful.

Preparing the MySQL database and tables

We create a test MySQL database and overall tables for demonstration purposes. If you have a database and tables in your environment, you can skip this step.

Log in to MySQL from the terminal using the MySQL root user and root user password.

1

# mysql -uroot -p

Copy after login

Create a database and tables

1

2

3

4

mysql> Create database test1;

mysql> use test1;

mysql> create table tab1(name varchar(30), owner varchar(30), species varchar(20), sex char(1));

Query OK, 0 rows affected (0.02 sec)

Copy after login

In addition, we will add some records to test the data

1

2

3

4

mysql> insert into tab1 values('Chandra','Prakash','Kadarla','m'),('Srinvas','Kadarla','Chary','m');

Query OK, 2 rows affected (0.00 sec)

Records: 2 Duplicates: 0 Warnings: 0

Then quit from the MySQL.

Copy after login

Backup of MySQL database

We need to use the command – MySQL dump to back up the MySQL database

1

# mysqldump --all-databases --user=root --password --master-data > backupDB.sql

Copy after login

For security reasons, we will obtain some configuration files of MySQL elsewhere in the system

1

# cp /etc/mysql/my.cnf /opt/my.cnf.bak

Copy after login

Uninstall the MySQL package

us MySQL will be uninstalled using the following command –

1

2

# service mysqld stop

# yum remove mysql-server mysql-client mysql-common

Copy after login

Install MariaDB package

MariaDB has been replaced by MySQL on all major Linux distribution official repositories. You can add the official repository even if you are using an older version of Linux.

Create the file in the yum repos directory

1

# sudo vi /etc/yum.repos.d/MariaDB.repo

Copy after login

Add the following content to the file and save it

1

2

3

4

5

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/5.5/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

Copy after login

To install the Maria-DB server and client, run the following commands .

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

# yum install MariaDB-server MariaDB-client

Loaded plugins: fastestmirror, langpacks

base                                  | 3.6 kB 00:00

extras                                | 3.4 kB 00:00

mariadb                               | 2.9 kB 00:00

updates                               | 3.4 kB 00:00

   --> Restarting Dependency Resolution with new changes.

   --> Running transaction check

   ---> Package MariaDB-shared.x86_64 0:5.5.49-1.el7.centos will be obsoleting

   ---> Package mariadb-libs.x86_64 1:5.5.35-3.el7 will be obsoleted

   --> Finished Dependency Resolution

Dependencies Resolved

========================================================================================

Package                         Arch          Version                      Repository    Size

========================================================================================

Installing:

   MariaDB-client             x86_64          5.5.49-1.el7.centos          mariadb          8.6 M

   MariaDB-server             x86_64          5.5.49-1.el7.centos          mariadb          40 M

   MariaDB-shared             x86_64          5.5.49-1.el7.centos          mariadb          1.0 M

      replacing mariadb-libs.x86_64 1:5.5.35-3.el7

Installing for dependencies:

   MariaDB-common             x86_64          5.5.49-1.el7.centos          mariadb          23 k

   perl-Compress-Raw-Bzip2    x86_64          2.061-3.el7                  base             32 k

   perl-Compress-Raw-Zlib     x86_64          1:2.061-4.el7                base             57 k

   perl-DBI                   x86_64          1.627-4.el7                  base             802 k

   perl-Data-Dumper           x86_64          2.145-3.el7                  base             47 k

   perl-IO-Compress           noarch          2.061-2.el7                  base             260 k

   perl-Net-Daemon            noarch          0.48-5.el7                   base             51 k

   perl-PlRPC                 noarch          0.2020-14.el7                base             36 k

Transaction Summary

========================================================================================

Install 3 Packages (+8 Dependent packages)

Total download size: 51 M

Is this ok [y/d/N]: y

Downloading packages:

warning: /var/cache/yum/x86_64/7/mariadb/packages/MariaDB-5.5.49-centos7-x86_64-common.rpm: Header V4 DSA/SHA1 Signature, key ID 1bb943db: NOKEY

Public key for MariaDB-5.5.49-centos7-x86_64-common.rpm is not installed

(1/11): MariaDB-5.5.49-centos7-x86_64-common.rpm             | 23 kB 00:00:01

(2/11): MariaDB-5.5.49-centos7-x86_64-client.rpm             | 8.6 MB 00:00:12

warning: /var/cache/yum/x86_64/7/base/packages/perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Public key for perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm is not installed

(3/11): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm       | 32 kB 00:00:00

(4/11): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm        | 57 kB 00:00:00

(5/11): perl-Data-Dumper-2.145-3.el7.x86_64.rpm              | 47 kB 00:00:00

(6/11): perl-IO-Compress-2.061-2.el7.noarch.rpm              | 260 kB 00:00:00

(7/11): perl-Net-Daemon-0.48-5.el7.noarch.rpm                | 51 kB 00:00:00

(8/11): perl-DBI-1.627-4.el7.x86_64.rpm                      | 802 kB 00:00:00

(9/11): perl-PlRPC-0.2020-14.el7.noarch.rpm                  | 36 kB 00:00:00

(10/11): MariaDB-5.5.49-centos7-x86_64-shared.rpm            | 1.0 MB 00:00:01

Total download size: 51 M

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

   Installing : MariaDB-common-5.5.49-1.el7.centos.x86_64          1/12

   Installing : perl-Data-Dumper-2.145-3.el7.x86_64                2/12

   Installing : MariaDB-client-5.5.49-1.el7.centos.x86_64          3/12

   Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64        4/12

   Installing : perl-Net-Daemon-0.48-5.el7.noarch                  5/12

   Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64         6/12

   Installing : perl-IO-Compress-2.061-2.el7.noarch                7/12

   Installing : perl-PlRPC-0.2020-14.el7.noarch                    8/12

   Installing : perl-DBI-1.627-4.el7.x86_64                        9/12

Installed:

   MariaDB-client.x86_64 0:5.5.49-1.el7.centos       MariaDB-server.x86_64 0:5.5.49-1.el7.centos

   MariaDB-shared.x86_64 0:5.5.49-1.el7.centos

Dependency Installed:

   MariaDB-common.x86_64 0:5.5.49-1.el7.centos       perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7

   perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7       perl-DBI.x86_64 0:1.627-4.el7

   perl-Data-Dumper.x86_64 0:2.145-3.el7             perl-IO-Compress.noarch 0:2.061-2.el7

   perl-Net-Daemon.noarch 0:0.48-5.el7               perl-PlRPC.noarch 0:0.2020-14.el7

Replaced:

   mariadb-libs.x86_64 1:5.5.35-3.el7

Complete!

Copy after login

After installing all the required packages, we need to set a password for the root user account. Root password recovery from MySQL backup configuration files.

1

# cp /opt/my.cnf /etc/mysql/

Copy after login

Now, we need to run the following command to restart the MariaDB service.

1

# service mariadb start

Copy after login

Import MySQL database

We must import the database we backed up from MySQL into MariaDB

1

# mysql -u root -p < backupDB.sql

Copy after login

Enter the password of the root user, and then the database will be imported to MariaDB

We need to check whether the database is restored correctly.

Please follow the following command –

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

# mysql -u root -p

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test1              |

+--------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]> use test1;

MariaDB [test01]> select * from tab1;

select * from tab1;

+---------+---------+---------+------+

| name    | owner   | species | sex  |

+---------+---------+---------+------+

| Chandra | Prakash | Kadarla |    m |

| Srinvas | Kadarla | Chary   |    m |

+---------+---------+---------+------+

2 rows in set (0.00 sec)

Copy after login

Now the migration from MySQL to MariaDB has been successfully completed.

After we run the command and follow the tutorial, we can migrate the database from MySQL to MariaDB in simple steps, where MariaDB has a lot of new features compared to MySQL. In the tutorial above I used a simple scenario to test the migration configuration.

The above is the detailed content of How to migrate MySQL to MariaDB on Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement? How do you drop a table in MySQL using the DROP TABLE statement? Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns? How do you create indexes on JSON columns? Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do you represent relationships using foreign keys? How do you represent relationships using foreign keys? Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles