当前位置: 首页 > 编程文章 >

MySQL 5.1.45 自动化编译安装脚本详解

MySQL 5.1.45 自动化编译安装脚本详解

作者:顾澄时间:2026-10-22 13:07:59浏览:643

针对手动安装 MySQL 在多台服务器环境下效率低下的问题,本文介绍了一个用于 MySQL 5.1.45 的自动化编译安装 Shell 脚本。该脚本将软件安装至指定目录,配置数据文件、日志及 my.cnf 配置文件路径,并指定使用 3309 端口。通过执行 install_mysql.sh,用户可实现从下载源码到验证数据库列表的一键式部署,显著提升运维效率。

本文目录展开

MySQL 5.1.45 自动化编译安装脚本详解

一、问题背景 当仅部署单台 MySQL 服务器时,手动操作尚可接受;但若需批量安装多台服务器,手动流程将变得繁琐且低效。为此,建议编写名为 install_mysql.sh 的 Shell 脚本来实现自动化安装过程。

二、程序配置说明 本方案将 MySQL 5.1.45 编译安装至 /home/longxibendi/mysql/usr/local/mysql 路径。 数据文件与日志文件存放于 /home/longxibendi/mysql/3309/ 目录下。 配置文件 my.cnf 同样位于 /home/longxibendi/mysql/3309 目录中。 服务监听端口设置为 3309。

三、源程序 install_mysql.sh


#!/bin/bash 
#author longxibendi 
#function install MySQL5.1.45 
 
###################################### configure and install ##################################################### 
mkdir -p /home/longxibendi/mysql/usr/local/mysql 
cd  
mkdir mysql 
cd mysql 
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.45.tar.gz 
 
tar zxvf mysql-5.1.45.tar.gz 
cd mysql-5.1.45 
 
 
./configure --prefix=/home/longxibendi/mysql/usr/local/mysql --without-debug --without-bench --enable-thread-safe-client --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-charset=latin1 --with-extra-charset=utf8,gbk --with-innodb --with-mysqld-user=longxibendi --without-embedded-server --with-server-sufix=community --with-unix-socket-path=/home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-plugins=partition,heap,innobase,myisam,myisammrg,csv 
make -j `cat /proc/cpuinfo | grep 'model name' | wc -l ` && make install 
 
 
###################################### set log and data storage path ##################################################### 
 
chmod +w /home/longxibendi/mysql/usr/local/mysql 
mkdir -p /home/longxibendi/mysql/3309/data/ 
mkdir -p /home/longxibendi/mysql/3309/binlog/ 
mkdir -p /home/longxibendi/mysql/3309/relaylog/ 

 
###################################### create data file ##################################################### 
 
/home/longxibendi/mysql/usr/local/mysql/bin/mysql_install_db --basedir=/home/longxibendi/mysql/usr/local/mysql --datadir=/home/longxibendi/mysql/3309/data --user=longxibendi 
 
####################################### create my.cnf profile ##################################################### 
 
echo " 
[client] 
character-set-server = utf8 
port  = 3309 
socket = /home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock 
 
[mysqld] 
character-set-server = utf8 
replicate-ignore-db = mysql 
replicate-ignore-db = test 
replicate-ignore-db = information_schema 
user  = mysql 
port  = 3309 
socket = /home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock 
basedir = /home/longxibendi/mysql 
datadir = /home/longxibendi/mysql/3309/data 
log-error = /home/longxibendi/mysql/3309/mysql_error.log 
pid-file = /home/longxibendi/mysql/3309/mysql.pid 
open_files_limit  = 10240 
back_log = 600 
max_connections = 5000 
max_connect_errors = 6000 
table_cache = 614 
external-locking = FALSE 
max_allowed_packet = 16M 
sort_buffer_size = 1M 
join_buffer_size = 1M 
thread_cache_size = 300 
#thread_concurrency = 8 
query_cache_size = 20M 
query_cache_limit = 2M 
query_cache_min_res_unit = 2k 
default-storage-engine = MyISAM 
thread_stack = 192K 
transaction_isolation = READ-COMMITTED 
tmp_table_size = 20M 
max_heap_table_size = 20M 
long_query_time = 3 
log-slave-updates 
log-bin = /home/longxibendi/mysql/3309/binlog/binlog 
binlog_cache_size = 4M 
binlog_format = MIXED 
max_binlog_cache_size = 8M 
max_binlog_size = 20M 
relay-log-index = /home/longxibendi/mysql/3309/relaylog/relaylog 
relay-log-info-file = /home/longxibendi/mysql/3309/relaylog/relaylog 
relay-log = /home/longxibendi/mysql/3309/relaylog/relaylog 
expire_logs_days = 30 
key_buffer_size = 10M 
read_buffer_size = 1M 
read_rnd_buffer_size = 6M 
bulk_insert_buffer_size = 4M 
myisam_sort_buffer_size = 8M 
myisam_max_sort_file_size = 20M 
myisam_repair_threads = 1 
myisam_recover 
 
interactive_timeout = 120 
wait_timeout = 120 
 
skip-name-resolve 
#master-connect-retry = 10 
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396 
 
#master-host   =  192.168.1.2 
#master-user   =  username 
#master-password =  password 
#master-port   = 3309 
 
server-id = 1 
 
innodb_additional_mem_pool_size = 16M 
innodb_buffer_pool_size = 20M 
innodb_data_file_path = ibdata1:56M:autoextend 
innodb_file_io_threads = 4 
innodb_thread_concurrency = 8 
innodb_flush_log_at_trx_commit = 2 
innodb_log_buffer_size = 16M 
innodb_log_file_size = 20M 
innodb_log_files_in_group = 3 
innodb_max_dirty_pages_pct = 90 
innodb_lock_wait_timeout = 120 
innodb_file_per_table = 0 
 
#log-slow-queries = /home/longxibendi/mysql/3309/slow.log 
#long_query_time = 10 
 
[mysqldump] 
quick 
max_allowed_packet = 32M 
 
" > /home/longxibendi/mysql/3309/my.cnf 
 
 
############################### solve bug http://bugs.mysql.com/bug.php?id=37942 ############################################# 
 
mkdir -p /home/longxibendi/mysql/share/mysql/english/ 
cp /home/longxibendi/mysql/usr/local/mysql/share/mysql/english/errmsg.sys /home/longxibendi/mysql/share/mysql/english/ 
 
############################### start MySQL Server ############################################# 
/bin/sh /home/longxibendi/mysql/usr/local/mysql/bin/mysqld_safe --defaults-file=/home/longxibendi/mysql/3309/my.cnf 2>&1 > /dev/null & 
############################### try use MySQL Server ############################################# 
/home/longxibendi/mysql/usr/local/mysql/bin/mysql -u root -p -S /home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock -P3309 -h127.0.0.1 -e "show databases;" 


#!/bin/bash
#author longxibendi
#function install MySQL5.1.45

###################################### configure and install #####################################################
mkdir -p /home/longxibendi/mysql/usr/local/mysql
cd 
mkdir mysql
cd mysql
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.45.tar.gz

tar zxvf mysql-5.1.45.tar.gz
cd mysql-5.1.45




./configure --prefix=/home/longxibendi/mysql/usr/local/mysql --without-debug --without-bench --enable-thread-safe-client --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-charset=latin1 --with-extra-charset=utf8,gbk --with-innodb --with-mysqld-user=longxibendi --without-embedded-server --with-server-sufix=community --with-unix-socket-path=/home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-plugins=partition,heap,innobase,myisam,myisammrg,csv
make -j `cat /proc/cpuinfo | grep 'model name' | wc -l ` && make install



###################################### set log and data storage path #####################################################

chmod +w /home/longxibendi/mysql/usr/local/mysql
mkdir -p /home/longxibendi/mysql/3309/data/
mkdir -p /home/longxibendi/mysql/3309/binlog/
mkdir -p /home/longxibendi/mysql/3309/relaylog/


###################################### create data file #####################################################

/home/longxibendi/mysql/usr/local/mysql/bin/mysql_install_db --basedir=/home/longxibendi/mysql/usr/local/mysql --datadir=/home/longxibendi/mysql/3309/data --user=longxibendi


####################################### create my.cnf profile #####################################################

echo "
[client]
character-set-server = utf8
port  = 3309
socket = /home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock

[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user  = mysql
port  = 3309
socket = /home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock
basedir = /home/longxibendi/mysql
datadir = /home/longxibendi/mysql/3309/data
log-error = /home/longxibendi/mysql/3309/mysql_error.log
pid-file = /home/longxibendi/mysql/3309/mysql.pid
open_files_limit  = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 16M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 20M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 20M
max_heap_table_size = 20M
long_query_time = 3
log-slave-updates
log-bin = /home/longxibendi/mysql/3309/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 20M
relay-log-index = /home/longxibendi/mysql/3309/relaylog/relaylog
relay-log-info-file = /home/longxibendi/mysql/3309/relaylog/relaylog
relay-log = /home/longxibendi/mysql/3309/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 10M
read_buffer_size = 1M
read_rnd_buffer_size = 6M
bulk_insert_buffer_size = 4M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 20M
myisam_repair_threads = 1
myisam_recover

interactive_timeout = 120
wait_timeout = 120

skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

#master-host   =  192.168.1.2
#master-user   =  username
#master-password =  password
#master-port   = 3309

server-id = 1

innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 20M
innodb_data_file_path = ibdata1:56M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 20M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0

#log-slow-queries = /home/longxibendi/mysql/3309/slow.log
#long_query_time = 10

[mysqldump]
quick
max_allowed_packet = 32M

" > /home/longxibendi/mysql/3309/my.cnf


############################### solve bug http://bugs.mysql.com/bug.php?id=37942 #############################################

mkdir -p /home/longxibendi/mysql/share/mysql/english/
cp /home/longxibendi/mysql/usr/local/mysql/share/mysql/english/errmsg.sys /home/longxibendi/mysql/share/mysql/english/

############################### start MySQL Server #############################################
/bin/sh /home/longxibendi/mysql/usr/local/mysql/bin/mysqld_safe --defaults-file=/home/longxibendi/mysql/3309/my.cnf 2>&1 > /dev/null &
############################### try use MySQL Server #############################################
/home/longxibendi/mysql/usr/local/mysql/bin/mysql -u root -p -S /home/longxibendi/mysql/usr/local/mysql/sock/mysql.sock -P3309 -h127.0.0.1 -e "show databases;"

四、成功安装结果

安装流程结束后,直接按回车键即可看到以下数据库列表信息: information_schema mysql test

以上即为 MySQL 5.1.45 编译安装的完整配置方法,希望能为读者提供有益参考。

上一篇
MySQL 5.1主从同步Relay log read failure错误解决方法

在使用MySQL 5.1进行主从复制时,常因版本Bug导致中继日志损坏,出现Relay log read failure错误,表现为Slave_SQL_Running状态为No及Last_Errno 1594。该问题通常由中继日志或主库二进制日志异常引起。通过定位准确的同步位置点(Master_Log_File和Exec_Master_Log_Pos),执行stop slave后使用change master命令重置同步源,再启动slave即可恢复同步。建议将MySQL升级至5.1.37sp1或5.1.40以上版本以规避此缺陷。

下一篇
Linux下Apache、MySQL、PHP源码编译安装配置指南

本文记录了在Linux环境下通过源码编译方式安装配置Apache 2.2.12、MySQL 5.0.56及PHP 5.3.0的详细过程。内容涵盖软件包获取、依赖库准备、各组件的configure参数详解、编译安装步骤以及服务启动与权限设置,旨在提供一套完整的LAMP环境部署参考方案。

相关文章

更多
CentOS 7.0编译安装LNMP环境教程

本文介绍在CentOS 7.0系统中通过源码编译方式搭建Nginx 1.6.0、MySQL 5.6.19和PHP 5.5.14组成的LNMP环境。主要步骤包括配置iptables防火墙、关闭SELinux、下载各组件源码包、安装依赖库,并依次编译安装MySQL、Nginx及PHP,最后进行开机自启设置与功能测试。

2026.11.15 740
CentOS 7 编译安装 MySQL 5.7 详细步骤

MySQL 5.7 GA版本已支持生产环境,具备多核CPU优化、原生JSON支持及健壮的复制功能等特性。本文详细介绍在CentOS系统中通过源码编译安装MySQL 5.7的完整流程,涵盖依赖包安装、Boost库配置、CMake预编译、make构建以及数据库初始化与密码设置等关键步骤。

2025.12.28 563
生产环境自动化部署MySQL 5.6安装脚本详解

本文介绍用于生产环境的MySQL 5.6自动化安装Shell脚本,该脚本已验证可用于正式库。默认启用innodb_buffer_pool_dump_at_shutdown和innodb_buffer_pool_load_at_startup以在重启时加载热数据块,但仅正常关闭数据库时才会dump数据。脚本预设root密码为MANAGER,目录结构包括/usr/local/mysql、/data/mysql等,内存参数innodb_buffer_pool_size默认设为512M,建议根据实际内存调整为50%-80%。

2026.04.22 473
Ubuntu 12.04 Server 编译安装 PHP 5.3 开发环境指南

在 Ubuntu 12.04 Server 环境中,当系统自带 PHP 5.4 而项目强制要求使用 PHP 5.3 时,直接降级可能导致兼容性问题。本文介绍通过源码编译方式在 Ubuntu 12.04 上构建包含 Apache 2.2、MySQL 5.5 及 PHP 5.3 的完整开发环境,解决版本依赖冲突。

2025.09.26 424
CentOS 7 手动编译安装 Nginx+PHP+MySQL 环境指南

本文介绍在 CentOS 7 系统下,通过手动编译源码的方式搭建 Nginx、PHP 和 MySQL 环境的完整流程。除了编译器使用 yum 安装外,其余组件均从源码编译,涵盖依赖库处理、参数配置及服务启动命令,适合追求最新版本的开发者参考。

2025.09.30 207
CentOS下PHP7编译安装及MySQL支持常见问题解决

本文介绍在CentOS系统中通过源码编译安装PHP7的过程,重点讲解如何启用mysqlnd驱动以替代传统的libmysql库,并详细列出configure参数的配置方法。针对编译时因内存不足导致的cc内部错误,以及运行时php.ini中pdo_mysql.default_socket路径不匹配导致无法连接MySQL的问题,提供了具体的排查步骤和解决方案,包括添加--disable-fileinfo参数、指定socket路径或创建软链接等实际操作。

2026.06.25 149

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。