Databases 15 min read

How to Install and Configure MySQL 5.7 on ARM (Aarch64) with Master‑Slave Replication

This guide walks through checking the OS architecture, preparing the environment, downloading the appropriate MySQL 5.7 packages for ARM, installing and configuring MySQL, setting up automatic startup and environment variables, initializing the server, securing the root account, and finally configuring master‑slave replication between two servers.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Install and Configure MySQL 5.7 on ARM (Aarch64) with Master‑Slave Replication

Check Operating System

#一定要注意查看本机的操作系统,是amd(x86)还是arm(aarch)架构
$ uname -a
Linux Server-58aa6d9e-9412-4ab6-b496-2adc0af4e9c8 4.19.90-17.5.ky10.aarch64 #1 SMP Fri Aug 7 13:35:33 CST 2020 aarch64 aarch64 aarch64 GNU/Linux
$ cat /etc/os-release
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Tercel)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Tercel)"
ANSI_COLOR="0;31"

注意:MsSQL8.0开始才支持arm架构,我们可以去第三方下载编译好的安装包,或者可以采取docker安装

Configure Basic Environment

#关闭防火墙禁止开机自动启动
systemctl stop firewalld.service && systemctl disable firewalld.service && service iptables stop
#关闭SELINUX
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
#创建mysql用户和组,mysql用户不能登录系统选项,不创建用户的主目录。
groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
#卸载系统自带的依赖包,会存在冲突
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-errmessage-10.3.9-9.p02.ky10.x86_64
rpm -qa | grep mysql
rpm -e --nodeps 删除已经安装的MYSQL包

Download Packages

#前往官方地址下载adm(x86)包
https://downloads.mysql.com/archives/community/
#前往华为镜像站下载arm(aarch)包
https://obs.cn-north-4.myhuaweicloud.com/obs-mirror-ftp4/database/mysql-5.7.27-aarch64.tar.gz

Upload to Server and Install

注意:服务器需要自己挂盘,建议统一挂载到/data目录

#解压安装包提取文件内容到/data目录
tar -xvf mysql-5.7.27-aarch64.tar.gz -C /data/
#修改文件夹名字简洁点
cd /data 
mv mysql-5.7.27-aarch64/ mysql/
#创建配置文件的软链接
ln -sf /data/mysql/my.cnf /etc/my.cnf
#创建数据目录
mkdir mysql_data mysql_tmp mysql_logs
#给目录授权
chown -R mysql:mysql /data/mysql /data/mysql_data /data/mysql_tmp  /data/mysql_logs
#覆盖依赖包
cp -rf /data/mysql/extra/lib* /usr/lib64/ 
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.old
ln -s /usr/lib64/libstdc++.so.6.0.24 /usr/lib64/libstdc++.so.6

1、修改配置文件

cd mysql
cp my.cnf my.cnf_bak #先备份
vim /etc/my.cnf	#再修改
[client]
# 客户端连接 MySQL 服务器的端口号,通常是 3306。
port = 3306
# MySQL 服务器的套接字文件路径,用于本地连接。
socket = /dev/shm/mysql.sock
[mysqld]
# MySQL 服务器监听的端口号,通常也是 3306。
port = 3306
# MySQL 服务器的套接字文件路径,用于本地连接。
socket = /dev/shm/mysql.sock
# MySQL 的根目录路径,通常用于安装 MySQL 的根目录。
basedir = /data/mysql
# 存放数据库文件的目录路径。
datadir = /data/mysql_data
# 启用binlog日志文件,可以指定目录,如果不指定则放在数据目录下面
log_bin = mysql-bin
#存放 MySQL 进程 ID 的文件路径。
pid-file = /data/mysql_data/mysql.pid
#错误日志路径
log_error = /data/mysql_logs/mysql-error.log
#慢查询sql日志路径
slow_query_log_file = /data/mysql_logs/mysql-slow.log
#临时数据路径
tmpdir=/data/mysql_tmp
#MySQL 服务器运行时使用的用户(通常是 "mysql" 用户)
user = mysql
#用于指定 MySQL 服务器绑定的 IP 地址,0.0.0.0 表示绑定到所有可用的 IP 地址。
bind-address = 0.0.0.0
# MySQL 服务器的唯一标识符,用于主从复制等。
server-id = 1
# 连接到 MySQL 服务器时初始化 SQL 命令。
init-connect = 'SET NAMES utf8mb4'
# 服务器默认的字符集。
character-set-server = utf8mb4
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
binlog_format = mixed
expire_logs_days = 30
slow_query_log = 1
long_query_time = 1
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 100M 
[myisamchk]
key_buffer_size = 8M  
sort_buffer_size = 8M 
read_buffer = 4M  
write_buffer = 4M

2、设置开机自动启动

# 设置系统引导时自动启动 MySQL 服务。
cp -rf /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl enable mysqld

3、添加环境变量

vim /etc/profile
# 在尾部添加
export MYSQL_HOME=/data/mysql
export PATH=$PATH:$MYSQL_HOME/bin
#刷新环境变量
source /etc/profile

4、初始化启动MySQL

#无密码初始化登录 
mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql_data
#开启mysql
systemctl start mysqld
#查看状态
systemctl status mysqld

5、修改MySQL密码,并允许远程连接

#先免密登录
mysql -u root
#使用mysql库
use mysql;
#更新root密码
update user set authentication_string=password("你的密码") where user="root";
#赋予所有IP都可以使用root用户远程连接的权限
grant all privileges  on *.* to root@'%' identified by "你的密码";
#刷新权限配置
flush privileges;
#退出mysql
exit

Master‑Slave Configuration

1. Environment Preparation

最少两台服务器,一主一从,两台主机上都安装好MySQL服务,/etc/my.cnf配置文件除了server-id不能一致,其他全部保持一致。

两台服务器需要能够互相访问3306监听端口。

2. Master Configuration

1、修改主库配置文件

# 要给从机同步的库(如果不写,默认全部同步)
#binlog-do-db=ganshuchang
# 不给从机同步的库(多个写多行)
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
#  启用二进制日志
log-bin=master-bin
#  服务器唯一ID,一般取IP最后一段
server-id=1
log_bin_index = home/mysql/binlog/mysql-bin.index

2、增加同步用户

#创建同步用户
create user 'repl'@'%' identified by 'repl';
#赋予同步权限
grant replication slave on *.* to 'repl'@'%';

3、重启服务

service mysqld restart

4、查看binlog文件(File 和 Position 将在从库配置中使用)

show master status\G;

3. Slave Configuration

1、修改从库配置文件

server-id = 2
# 加上以下参数可以避免更新不及时,SLAVE 重启后导致的主从复制出错
#设置从库只读状态,避免在从库上写操作,但该指令对超级管理员是无效的,mysql5.7增加了一个新的参数super_read_only,该参数使得超级管理员也无法进行写操作。但是super_read_only这个参数大部分都是关闭掉的
read_only = 1
#指定了主服务器的信息应该存储在特殊的表中。
master_info_repository=TABLE
#指定中继日志(Relay Log)的信息存储在一个特殊的表中
relay_log_info_repository=TABLE
#这是中继日志的名称
relay-log = slave-relay-bin

2、重启服务

service mysqld restart

3、配置主从信息

CHANGE MASTER TO
MASTER_HOST = 'master_ip',  -- 主服务器的 IP 地址
MASTER_USER = 'replication',
MASTER_PASSWORD = 'password',
MASTER_LOG_FILE = 'mysql-bin.000001',  -- 主服务器的二进制日志文件名
MASTER_LOG_POS = 123;  -- 主服务器的二进制日志位置

4、启动复制

START SLAVE;

5、检查复制状态

#确保 Slave_IO_Running 和 Slave_SQL_Running 都显示为 "Yes",表示复制正常运行。
#如果Slave_IO_Running: Connecting,请检查:从库是否能远程登录repl用户,如果不能,检查配置文件是否限制,防火墙是否关闭
SHOW SLAVE STATUS\G;

6. 常用导库语句

#执行sql文件
mysql -uroot -p -D database_name > file.sql
#导出整个数据库
mysqldump -u username -p database_name > dumpfile.sql
#导出单个表
mysqldump -u username -p database_name table_name > table_dump.sql
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseLinuxmysqlReplicationARM
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.