===============================================
此安装程序分为两个结构,一个是安装脚本,一个是配置文件目录,其结构如下:
[root@helloween /]# tree /mysql_pro/
mysql_pro/├── dconfig│ ├── my.cnf│ ├── mysql-5.1.50.tar.gz│ └── varconfig└── install.sh1 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 = 3306socket = /usr/local/mysql/tmp/mysql.sock[mysqld]datadir=/data/dbdata/basedir = /usr/local/mysql/skip-name-resolvelower_case_table_names=1innodb_file_per_table=1expire_logs_days = 10federatedport = 3306socket = /usr/local/mysql/tmp/mysql.sockback_log = 50max_connections = 330max_connect_errors = 1000table_open_cache = 2048max_allowed_packet = 16Mbinlog_cache_size = 2Mmax_heap_table_size = 64Msort_buffer_size = 8Mjoin_buffer_size = 4Mthread_cache_size = 64thread_concurrency = 8query_cache_size = 128Mquery_cache_limit = 2Mft_min_word_len = 4default-storage-engine = innodbthread_stack = 192Ktransaction_isolation = REPEATABLE-READtmp_table_size = 128Mlog-bin=mysql-binbinlog_format=mixedslow_query_loglong_query_time = 0.5server-id = 1key_buffer_size = 8Mread_buffer_size = 2Mread_rnd_buffer_size = 2Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 10Gmyisam_repair_threads = 1myisam_recoverinnodb_additional_mem_pool_size = 32Minnodb_buffer_pool_size = 8Ginnodb_data_file_path = ibdata1:10M:autoextendinnodb_file_io_threads = 8innodb_thread_concurrency = 16innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 16Minnodb_log_file_size = 128Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 60innodb_lock_wait_timeout = 120[mysqldump]quickmax_allowed_packet = 256M[mysql]no-auto-rehashprompt=\\u@\\d \\R:\\m>[myisamchk]key_buffer_size = 512Msort_buffer_size = 512Mread_buffer = 8Mwrite_buffer = 8M[mysqlhotcopy]interactive-timeout[mysqld_safe]open-files-limit = 8192[root@helloween dconfig]#===============================================
做完以上步骤即可使用mysql服务了。
以上为个人见解,错误之处敬请指正。
指导老师:双星科技曾勇老师