最近弄了个S905X3的盒子刷完Armbian OS (基于ubuntu24),开始折腾Arm64之旅。第一站就遇到了MySQL的问题,由于MySQL没有提供Arm64版本,又不想塞Docker镜像,因此选择源码来编译MySQL5.7。下面记录详细过程和遇到的一些问题
CMAKE
最新的mysql均采用cmake的环境,因此要编译从cmake开始。Armbian OS默认安装的都是精简系统,得自行安装一下cmake
apt install cmake
至于BuildEssiontial,貌似默认就带了,于是继续往下走
万年的MySQL57,万年的OPENSSL1.1
要装MySQL,一个蛋疼的组件就是OPENSSL,众所周知从ubuntu22开始,openssl 1.1版就已经没有在默认库带上了。其它系统上还可以通过强制指定库来处理,Arm系统下,只得自己下来源码编译
wget https://mirrors.tencent.com/openssl/source/old/1.1.1/openssl-1.1.1v.tar.gz
然后展开后一路make && make install就好了
下载MYSQL57源码
下载最新带boost的源码包
https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.44.tar.gz
下来后然后展开
tar -xvf mysql-boost-5.7.44.tar.gz
然后把依赖更新一下,对于ubuntu24来说,是这几个
apt-get install libncurses-dev
apt install pkg-config
apt install libtirpc-dev
补丁&开始编译
源码展开后,要补丁一下,否则mysql client工具会报segmentation fault错误无法使用:
在源码解压文件中,找到terminal.h源码文件并编辑
find / -name "terminal.h" -print | head -n 1 | xargs vi
将其中的ifdef __sun 段注释掉完全开放
修改后是这样
/* #ifdef __sun */
extern int tgetent(char *, const char *);
extern int tgetflag(char *);
extern int tgetnum(char *);
extern int tputs(const char *, int, int (*)(int));
extern char* tgoto(const char*, int, int);
extern char* tgetstr(char*, char**);
/* #endif */
然后就可以开始编译了,进入mysql展开的目录(我的是展开到了/opt/setups/mysql/mysql-5.7.44),执行以下代码先开启4核(我的HK1BOX是4核ARM):
export MAKEFLAGS=-j4
进入到展开的源码目录执行,然后下面是编译命令:
cmake . -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/opt/setups/mysql/mysql-5.7.44/boost/
最好加个nohup后台执行,因为太。。。。漫长了。
在我的小盒子里开4个线程,7W的满载功率,跑了1个小时才编译完,这还是开4线程跑的
幸好改装了风扇压住了温度,最高保持在50度(室温25)
配置MYSQL
建立一个MYSQL用户,然后把目标目录授权给该用户
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
chown -R mysql:mysql /usr/local/mysql
把mysql加入到路径,这样后面执行命令就方便了
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
优化一下配置,对于我们这种小盒子系统,资源占用越小越好
vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/opt/mysql/data
socket=/opt/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0log-error=/opt/mysql/mysqld.log
pid-file=/opt/mysql/mysqld.pid#密码检查规则关闭
#validate_password=offmax_allowed_packet = 16M
skip-character-set-client-handshake
default-storage-engine=INNODB
character_set_server=utf8mb4
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
lower_case_table_names=1
max_connections=1000server-id=1
log-bin=mysql-bin
expire_logs_days=7performance_schema_max_table_instances=200
table_definition_cache=200
table_open_cache=128
然后按配置的初始化一下目录和权限
mkdir -p /opt/mysql/data
chown -R mysql:mysql /opt/mysql/
执行初始化
mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
然后查看root默认密码:
cat /opt/mysql/mysqld.log | grep "temporary password"
写个启动服务
vi /etc/systemd/system/mysqld.service
内容如下:
[Unit]
Description=MySQL Server Daemon
After=network.target[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/opt/mysql/mysqld.pid
ExecStart=/usr/local/mysql/bin/mysqld --daemonize
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=120
TimeoutStopSec=10
KillMode=process
Restart=on-failure
LimitNOFILE=5000[Install]
WantedBy=multi-user.target
然后设置自启动:
systemctl enable mysqld
前面都正确的话,应该本地就可以用root+初始密码进入了
mysql -uroot -p"Mu>aiR,Zx502" mysql
然后修改下默认密码,例如:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'admin'
重启mysqld服务,完事