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

此安装程序分为两个结构,一个是安装脚本,一个是配置文件目录,其结构如下:

[root@helloween /]# tree /mysql_pro/

mysql_pro/
├── dconfig
│   ├── my.cnf
│   ├── mysql-5.1.50.tar.gz
│   └── varconfig
└── install.sh
1 directory, 4 files
[root@helloween /]#

其中:

my.cnf是编译安装之后,服务要用到的服务端配置文件

varconfig是安装时,安装脚本用到的一些变量配置文件

mysql-5.1.50.tar.gz是安装源码包

install.sh是安装时需要执行的脚本文件,执行成功后,mysql服务器即可搭建成功

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

以下是各个文件的具体内容:

------------------------------------------------------------------------------------------------------

[root@helloween dconfig]# cat varconfig

#安装包名
V_name="mysql-5.1.50.tar.gz"
#解压包目录名
D_name="mysql-5.1.50"
#编译安装参数变量
Conf_arguments="'--prefix=/usr/local/mysql' '--localstatedir=/data/dbdata' '--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock' '--with-charset=utf8' '--with-extra-charsets=complex' '--with-pthread' '--enable-thread-safe-client' '--with-ssl' '--with-client-ldflags=-all-static' '--with-mysqld-ldflags=-all-static' '--with-plugins=partition,federated,ndbcluster,innobase,csv,blackhole,myisam,innodb_plugin,heap,archive' '--enable-shared' '--enable-assembler'"
#数据文件目录变量
Data_dir=:"/data/dbdata"
#安装目录变量
Base_dir="/usr/local/mysql"
#初始化参数变量
Init_arguments="--user=mysql --basedir=${Base_dir} --datadir=${Data_dir}"
[root@helloween dconfig]#

------------------------------------------------------------------------------------------------------

[root@helloween mysql_pro]# cat install.sh

#!/bin/bash
#written by helloween
#2014-4-19
#mysql-install
#====================================
#配置文件检查函数
CheckConfig()
{
   if [ -f my.cnf -a -f varconfig -a -f ${V_name} ];then
       echo "OK!config_file exists,it will be continue!"
   else
       echo "Error!config_file not exists,it will be quit!"
       exit
   fi
}
Main()
{
   #进入配置文件目录
   [ -d ./dconfig ] && cd ./dconfig
   #安装前进行变量设置
   . varconfig
   #检查配置文件
   CheckConfig;
   #安装依赖包
   yum -y install gcc gcc-c++ ncurses ncurses-devel openssl openssl-devel libtool* >/dev/null 2>&1
   #解压安装包
   tar xf $V_name >/dev/null 2>&1
   #进入安装目录
   cd $D_name
   #开始进行编译安装
   ./configure $Conf_arguments && make && make install
  #初始化
   id mysql || useradd mysql
   mkdir $Data_dir
   chown -R mysql:mysql  $Base_dir
   chown -R mysql:mysql  $Data_dir
   $Base_dir/bin/mysql_install_db  $Init_arguments
   /bin/cp /usr/local/mysql/share/mysql/mysql.server  /etc/init.d/mysqld
   chmod 755 /etc/init.d/mysql
   sed -i "/^basedir=/d" /etc/init.d/mysql
   echo "basedir=${Base_dir}" >> /etc/init.d/mysql
   sed -i "/^datadir=/d" /etc/init.d/mysql
   echo "datadir=${Data_dir}" >>/etc/init.d/mysql
   #开机启动服务和设置环境变量
   sed -i '/^MYSQL=/d' /etc/profile
   echo "MYSQL=/usr/local/mysql/bin">>/etc/profile
   sed -i '/^PATH=$PATH:$MYSQL/d'
   echo 'PATH=$PATH:$MYSQL'>>/etc/profile
   echo "export PATH">>/etc/profile
   source /etc/profile
   #配置文件
   /bin/cp ./my.cnf  /etc
   #启动服务
   /etc/init.d/mysqld start
}
Main;
------------------------------------------------------------------------------------------------------

[root@helloween dconfig]# cat my.cnf | grep -v "^#" | grep -v "^$"

[client]
port        = 3306
socket        = /usr/local/mysql/tmp/mysql.sock
[mysqld]
datadir=/data/dbdata/
basedir = /usr/local/mysql/
skip-name-resolve
lower_case_table_names=1
innodb_file_per_table=1
expire_logs_days = 10
federated
port        = 3306
socket        = /usr/local/mysql/tmp/mysql.sock
back_log = 50
max_connections = 330
max_connect_errors = 1000
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 2M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 4M
thread_cache_size = 64
thread_concurrency = 8
query_cache_size = 128M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = innodb
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
log-bin=mysql-bin
binlog_format=mixed
slow_query_log
long_query_time = 0.5
server-id = 1
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 32M
innodb_buffer_pool_size = 8G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 60
innodb_lock_wait_timeout = 120
[mysqldump]
quick
max_allowed_packet = 256M
[mysql]
no-auto-rehash
prompt=\\u@\\d \\R:\\m>
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
[root@helloween dconfig]#

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

做完以上步骤即可使用mysql服务了。

以上为个人见解,错误之处敬请指正。

指导老师:双星科技曾勇老师