Migrate MySQL to MariaDB

From WikiMLT

Here is how I've mi­grat­ed one Word­Press in­stance from MySQL to Mari­aDB at Ubun­tu Serv­er 22.04 on LXC on Ubun­tu 22.04 VPS on Dig­i­talO­cean.

Back­up the Ex­ist­ing Data­bas­es and Set­tings

In this case I need to ex­port just one da­ta base. This is wp_​​​example_​​​com.

sudo mysqldump --all-databases > ~/tmp/all_data_bases_master_data.sql  # Export all DBs just in case
sudo mysqldump --databases 'wp_example_com' > wp_example_com.sql       # Export the target DB also create a copy
sudo cp -R /etc/mysql ~/tmp/                                           # Create a copy of the existing settings
  • --master-data is dep­re­cat­ed in Mari­aDB so it is not used with­in the dump com­mand.

Re­move the Ex­ist­ing MySQL Serv­er and Client

sudo systemctl stop mysql
sudo apt update
sudo apt remove mysql-client
sudo apt remove mysql-client-8.0
sudo apt remove mysql-client-core-8.0
sudo apt remove mysql-server
sudo apt remove mysql-server-8.0
sudo apt remove mysql-server-core-8.0
sudo apt remove mysql-common
sudo apt autoremove 
sudo apt autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql* /etc/mysql

In­stall Mari­aDB Serv­er and Client

sudo apt install mariadb-server mariadb-client mariadb-common automysqlbackup
sudo mysql_secure_installation # switch to socket authentication

Try to lo­gin as root or use the mysqlad­min com­mand.

sudo mysql
mysqladmin --print-defaults

Im­port the Data­bas­es in­to Mari­aDB

In this step the things ac­tu­al­ly didn't went flu­ent­ly as I've ex­pect­ed, so here is what I've fi­nal­ly done: cre­ate the data­base and the rel­e­vant user with­in the MariaDB's CLI. Solve the ERROR 1273 (HY000) at line 22: Unknown collation: 'utf8mb4_0900_ai_ci' and fi­nal­ly im­port the data­base.

sudo mysql
CREATE DATABASE wp_example_com;
CREATE OR REPLACE USER 'wp_example_com_user'@'localhost' IDENTIFIED BY 'strong-passwd';
GRANT ALL PRIVILEGES ON wp_example_com.* TO 'wp_example_com_user'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SHOW DATABASES;
exit
sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' wp_example_com.sql
sudo mysql 'wp_example_com' < wp_example_com.sql

Con­clu­sion

The mi­gra­tion was not dif­fi­cult process and the time I've writ­ing this ar­ti­cle was much longer than the ac­tu­al ex­ec­u­tive of the mi­gra­tion steps took. My first im­pres­sion is that, the Word­Press ini­tial in­stance re­sponse much faster. Af­ter the DB mi­gra­tion I've up­dat­ed Word­Press to ver­sion 6.0 and al­so about 20 plu­g­ins – every­thing went pret­ty well.

Ref­er­ences


Mari­aDB vs. MySQL for En­ter­pris­es