Mysql安装脚本

Mysql安装脚本,来自于DBA Eugene
#!/bin/sh
#****************************************************************#
# ScriptName: install_mysql.sh
# Author: Eugene
# Create Date: 2009-03-20
# Modify Author:
# Modify Date: 2009-03-20
# Function:
#***************************************************************#
#install mysql software script--version: mysql-5.1.36
#scp root@10.0.65.61:/disk3/nfs/software/mysqldb/mysql-5.1.32.tar.gz /home/

tar zxvf /home/platvt/software/mysql-5.1.36.tar.gz

#Need judgeing group and user is exist
groupadd -g 601 mysql
useradd -c "mysql software owner" -g mysql -u 601 mysql

mkdir -p /usr/local/mysql/log
mkdir /usr/local/mysql/sock

cd /usr/local/
chown -R mysql.mysql mysql

#su - mysql

mkdir -p /home/mysql/mysqldata/binlog
mkdir /home/mysql/mysqldata/mydata
mkdir /home/mysql/mysqldata/tmpdir
mkdir /home/mysql/mysqldata/innodb_ts
mkdir /home/mysql/mysqldata/innodb_log

cd /home
chown -R mysql.mysql mysql

cd ~
mkdir /data
ln -s /home/mysql/mysqldata /data/mysqldata

cd /home/platvt/software/mysql-5.1.36

#make clean
yum install ncurses-devel

#****************************************************************************
#--with-system-type    Set the system type, like "sun-solaris10"

./configure --prefix=/usr/local/mysql \
--with-mysqld-user=mysql \
--without-debug \
--without-bench \
--with-pthread \
--enable-thread-safe-client \
--enable-assembler \
--enable-profiling \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--with-charset=utf8 \
--with-extra-charset=utf8,gbk \
--with-collation=utf8_bin \
--with-innodb \
--with-plugin-PLUGIN \
--with-csv-storage-engine \
--with-federated-storage-engine \
--with-big-tables \
--with-mysqld-user=mysql \
--with-partition \
--without-embedded-server \
--with-server-suffix=-community \
--with-unix-socket-path=/usr/local/mysql/sock/mysql.sock

make ; make install

#****************************************************************************
#write my.cnf

echo "[client]" > /etc/my.cnf
echo "port = 3306" >> /etc/my.cnf
echo "socket = /usr/local/mysql/sock/mysql.sock" >> /etc/my.cnf
echo "default-character-set = utf8" >> /etc/my.cnf

echo "    " >> /etc/my.cnf
echo "[mysqld]" >> /etc/my.cnf
echo "user=mysql" >> /etc/my.cnf
echo "port = 3306" >> /etc/my.cnf
echo "socket = /usr/local/mysql/sock/mysql.sock" >> /etc/my.cnf
echo "pid-file=/usr/local/mysql/sock/mysql.pid" >> /etc/my.cnf
echo "datadir=/data/mysqldata/mydata" >> /etc/my.cnf
echo "tmpdir =/data/mysqldata/tmpdir" >> /etc/my.cnf

echo "#init_file=/usr/local/mysql/etc/init.sql" >> /etc/my.cnf

echo " ">> /etc/my.cnf

echo "skip-locking" >> /etc/my.cnf
echo "skip-name-resolve" >> /etc/my.cnf
echo "lower_case_table_names=1" >> /etc/my.cnf

echo "back_log=100" >> /etc/my.cnf
echo "interactive_timeout=172800" >> /etc/my.cnf

echo " ">> /etc/my.cnf

echo "default-storage-engine = INNODB" >> /etc/my.cnf
echo "#default_table_type = MYISAM" >> /etc/my.cnf
echo "default-character-set = utf8" >> /etc/my.cnf

echo "max_connections = 500" >> /etc/my.cnf
echo "max_connect_errors=100000" >> /etc/my.cnf
echo "max_allowed_packet = 4M" >> /etc/my.cnf
echo "max_heap_table_size = 1024M" >> /etc/my.cnf
echo "max_length_for_sort_data = 4096" >> /etc/my.cnf

echo "     " >> /etc/my.cnf
echo "net_buffer_length = 8K" >> /etc/my.cnf
echo "sort_buffer_size = 8M" >> /etc/my.cnf
echo "join_buffer_size = 16M" >> /etc/my.cnf
echo "         " >> /etc/my.cnf
echo "table_cache = 1024" >> /etc/my.cnf
echo "thread_cache_size = 512" >> /etc/my.cnf
echo "thread_concurrency = 8" >> /etc/my.cnf
echo "query_cache_type=0" >> /etc/my.cnf
echo "#query_cache_size = 1800M" >> /etc/my.cnf
echo "query_cache_limit = 2M" >> /etc/my.cnf

echo "#memory table max size" >> /etc/my.cnf
echo "tmp_table_size = 128M" >> /etc/my.cnf


echo "#*******************************    Logs related settings ***************************" >> /etc/my.cnf
echo "log-error=/usr/local/mysql/log/error.log" >> /etc/my.cnf
echo "long_query_time = 1" >> /etc/my.cnf
echo "log_long_format" >> /etc/my.cnf
echo "binlog-format=mixed" >> /etc/my.cnf

echo "     " >> /etc/my.cnf

echo "#slow_query_log=/usr/local/mysql/log/slow-query.log" >> /etc/my.cnf
echo "log_slow_queries=/usr/local/mysql/log/slow-query.log" >> /etc/my.cnf

echo "log_queries_not_using_indexes" >> /etc/my.cnf

echo "binlog_cache_size = 2M" >> /etc/my.cnf
echo "max_binlog_size = 512M" >> /etc/my.cnf
echo "log-bin=/data/mysqldata/binlog/mysql-bin" >> /etc/my.cnf

echo "#log warnings" >> /etc/my.cnf
echo "log_warnings" >> /etc/my.cnf

echo "#*******************************    Replication related settings **********************" >> /etc/my.cnf
echo "#master" >> /etc/my.cnf
echo "server-id = 1" >> /etc/my.cnf

#echo "#Slave" >> /etc/my.cnf
#echo "server-id = 2" >> /etc/my.cnf
#echo "replicate_ignore_db=test" >> /etc/my.cnf
#echo "#replicate_ignore_db=mysql" >> /etc/my.cnf

echo "#******************************* MyISAM Specific options ****************************" >> /etc/my.cnf
echo "key_buffer_size = 32M" >> /etc/my.cnf
echo "read_buffer_size = 2M" >> /etc/my.cnf
echo "read_rnd_buffer_size = 16M" >> /etc/my.cnf
echo "bulk_insert_buffer_size = 16M" >> /etc/my.cnf
echo "myisam_sort_buffer_size = 64M" >> /etc/my.cnf
echo "myisam_max_sort_file_size = 10G" >> /etc/my.cnf
echo "myisam_max_extra_sort_file_size = 10G" >> /etc/my.cnf
echo "myisam_repair_threads = 1" >> /etc/my.cnf
echo "myisam_recover" >> /etc/my.cnf

echo "# ***************************** INNODB Specific options ****************************" >> /etc/my.cnf
echo "innodb_file_per_table" >> /etc/my.cnf
echo "transaction_isolation = REPEATABLE-READ" >> /etc/my.cnf

echo " ">> /etc/my.cnf

echo "innodb_additional_mem_pool_size = 16M" >> /etc/my.cnf
echo "innodb_buffer_pool_size = 1024M" >> /etc/my.cnf

echo "innodb_data_home_dir = /data/mysqldata/innodb_ts" >> /etc/my.cnf
echo "innodb_data_file_path = ibdata1:256M:autoextend" >> /etc/my.cnf

echo "innodb_file_io_threads = 4" >> /etc/my.cnf
echo "innodb_thread_concurrency = 0" >> /etc/my.cnf
echo "innodb_flush_log_at_trx_commit = 1" >> /etc/my.cnf

echo "innodb_log_buffer_size = 8M" >> /etc/my.cnf
echo "innodb_log_file_size = 512M" >> /etc/my.cnf
echo "innodb_log_files_in_group = 2" >> /etc/my.cnf

echo "innodb_log_group_home_dir = /data/mysqldata/innodb_log" >> /etc/my.cnf
echo "innodb_max_dirty_pages_pct = 20" >> /etc/my.cnf
echo "innodb_lock_wait_timeout = 120" >> /etc/my.cnf
echo "innodb_flush_method=O_DIRECT" >> /etc/my.cnf

echo "[mysqldump]" >> /etc/my.cnf
echo "quick" >> /etc/my.cnf

echo "max_allowed_packet = 2G" >> /etc/my.cnf

echo "[mysql]" >> /etc/my.cnf
echo "no-auto-rehash" >> /etc/my.cnf
echo "prompt=\"\\\u@\\\h : \\\d \\\r:\\\m:\\\s> \"" >> /etc/my.cnf
echo "#tee=\"/tmp/query.log\"" >> /etc/my.cnf
echo "#pager=\"less -i -n -S\"" >> /etc/my.cnf

echo "[myisamchk]" >> /etc/my.cnf
echo "key_buffer = 512M" >> /etc/my.cnf
echo "sort_buffer_size = 512M" >> /etc/my.cnf
echo "read_buffer = 8M" >> /etc/my.cnf
echo "write_buffer = 8M" >> /etc/my.cnf

echo "[mysqlhotcopy]" >> /etc/my.cnf
echo "interactive-timeout" >> /etc/my.cnf
echo "    " >> /etc/my.cnf
echo "[mysqld_safe]" >> /etc/my.cnf
echo "open-files-limit = 8192" >> /etc/my.cnf

#****************************************************************************
#general system database
/usr/local/mysql/bin/mysql_install_db
【注意】
1、软件Mysql下载FTP:http://10.20.153.22/software/mysql下
2、Mysql在Ubuntu上安装,提示缺少ncurses-devel
解决办法: sudo apt-get install libncurses5-dev 或者:sudo apt-get install ncurses-dev
sudo apt-get install gobjc++