mysql自動安裝腳本

爲適應自己工作習慣和需要,花一點時間寫了一個mysql自動安裝腳本,供大家參考學習。

注意:

1、需要先安裝cmake

2、數據庫版本需要在第二步安裝mysql時修改

3、該腳本是以root用戶安裝並啓動

腳本內容如下:

########################################################################

#mysql自動安裝腳本,其中變量/mysql_v_dir/和/port/可根據實際需要修改    #

#執行腳本命令:sh mysql_install.sh >mysql_install.log                  #

########################################################################

 

####0.定義mysql目錄####

mk_mysqldir=/tmp/setup                ##mysql安裝包所在目錄

mysql_v_dir=mysql_5611                ##mysql version directry

mysql_dir=/home/mysql/$mysql_v_dir    ##the path where mysql install

port=5611                             ##端口號

####1.創建mysql用戶和組####

#user=`cat /etc/passwd |grep mysql`

#if [ -z $user ]

#then

#groupadd mysql

#useradd mysql -d /home/mysql -g mysql

#else

#userdel mysql

#groupdel mysql

#groupadd mysql

#useradd mysql -d /home/mysql -g mysql

#fi

cd /home/mysql

mkdir $mysql_v_dir

cd $mysql_dir

mkdir data log tmp etc

#chown mysql:mysql data log tmp etc

 

####2.安裝mysql####

cd $mk_mysqldir

tar -xzf mysql-5.6.16.tar.gz

cd mysql-5.6.16

##cmake install##

cmake  \

-DCMAKE_INSTALL_PREFIX=${mysql_dir}  \

-DINSTALL_MYSQLDATADIR=${mysql_dir}/data  \

-DMYSQL_DATADIR=${mysql_dir}/data \

-DSYSCONFDIR=${mysql_dir}/etc    \

-DWITH_INNOBASE_STORAGE_ENGINE=1  \

-DDEFAULT_CHARSET=utf8   \

-DDEFAULT_COLLATION=utf8_general_ci  \

-DMYSQL_TCP_PORT=5535  \

-DMYSQL_UNIX_ADDR=${mysql_dir}/tmp/mysql.sock  \

-DWITH_EXTRA_CHARSETS=all

 

make ; make install

 

####3.創建並修改配置文件#####

cat <<EOF >$mysql_dir/etc/my.cnf

[client]

port            = $port

socket          = $mysql_dir/tmp/mysql.sock

 

[mysqld]

 

 

port                = $port

basedir         = $mysql_dir/

socket              = $mysql_dir/tmp/mysql.sock

pid-file        = $mysql_dir/data/mysql.pid

datadir         = $mysql_dir/data/

 

 

tmpdir              = $mysql_dir/tmp/

slave-load-tmpdir   = $mysql_dir/tmp/

# skip lever

skip-name-resolve

skip-symbolic-links

skip-external-locking

skip-slave-start

 

#thread level

 

 

table_open_cache = 2048

 

#############connect############

back_log                 = 50

max_connections          = 1000

max_connect_errors       = 10000

#open_files_limit         = 10240

 

##############timeout###########

connect-timeout          = 10

wait-timeout             = 800

interactive-timeout      = 800

slave-net-timeout        = 60

net_read_timeout         = 30

net_write_timeout        = 60

net_retry_count          = 10

net_buffer_length        = 16384

max_allowed_packet       = 64M

 

################# cache #############

table_open_cache              = 2048

thread_stack             = 192K

thread_cache_size        = 100

thread_concurrency       = 16

 

# qcache settings

query_cache_size         = 20m

query_cache_limit        = 2M

query_cache_min_res_unit = 2K

 

# default settings

# time zone

default-time-zone        = system

character-set-server     = utf8

default-storage-engine   = InnoDB

 

# tmp & heap

tmp_table_size           = 512M

max_heap_table_size      = 512M

 

log-bin                  = mysql-bin

log-bin-index            = mysql-bin.index

relay-log                = relay-log

relay_log_index          = relay-log.index

 

# warning & error log

log-warnings             = 1

log-error       = $mysql_dir/log/mysql.err

 

log-output               = FILE

 

# slow query log

slow_query_log           = 1

long-query-time          = 1

slow_query_log_file      = $mysql_dir/log/slow.log

#log-queries-not-using-indexes

#log-slow-slave-statements

 

general_log              = 1

general_log_file         = $mysql_dir/log/mysql.log

max_binlog_size          = 1G

max_relay_log_size       = 1G

 

# if use auto-ex, set to 0

relay-log-purge          = 1

 

# max binlog keeps days

expire_logs_days         = 7

 

binlog_cache_size        = 1M

 

# replication

#replicate-wild-ignore-table     = mysql.%

#replicate-wild-ignore-table     = test.%

# slave_skip_errors=all

 

key_buffer_size                 = 30M

sort_buffer_size                = 2M

read_buffer_size                = 2M

join_buffer_size                = 8M

read_rnd_buffer_size            = 8M

bulk_insert_buffer_size         = 64M

myisam_sort_buffer_size         = 64M

myisam_max_sort_file_size       = 10G

myisam_repair_threads           = 1

myisam_recover

 

group_concat_max_len            = 64K

 

transaction_isolation           = REPEATABLE-READ

 

innodb_file_per_table

#############mysql5.5new################

innodb_file_format = Barracuda

########################################

 

innodb_additional_mem_pool_size = 10M

innodb_buffer_pool_size         = 200M

innodb_data_home_dir            = $mysql_dir/data/

innodb_data_file_path           = ibdata1:100M:autoextend

 

################mysql5.5new############

innodb_read_io_threads          = 8

innodb_write_io_threads         = 8

innodb_purge_threads            = 1

########################################

 

innodb_thread_concurrency       = 16

innodb_flush_log_at_trx_commit  = 1

 

innodb_log_buffer_size          = 16M

innodb_log_file_size            = 50M

innodb_log_files_in_group       = 2

innodb_log_group_home_dir       = $mysql_dir/data/

 

innodb_max_dirty_pages_pct      = 90

innodb_lock_wait_timeout        = 50

#innodb_flush_method            = O_DSYNC

 

 

################mysql5.6 new#####################

innodb_buffer_pool_instances    = 16

innodb_change_buffering         = all

innodb_adaptive_flushing        = 1

innodb_io_capacity              = 2000

innodb_old_blocks_time          = 1000

innodb_stats_on_metadata        = 0

#################################################

 

old-passwords                   = 0

 

[mysqldump]

quick

max_allowed_packet              = 64M

 

[mysql]

no-auto-rehash

default-character-set           = utf8

connect-timeout                 = 3

 

[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

 

[mysqlhotcopy]

interactive-timeout

EOF

 

####4.初始化數據庫並啓動####

cd $mysql_dir/scripts

./mysql_install_db --basedir=$mysql_dir --datadir=$mysql_dir/data --user=root

cd $mysql_dir/bin

./mysqld_safe --defaults-file=$mysql_dir/etc/my.cnf --user=root &

####5.添加mysql命令到環境變量中####

echo "export PATH=$mysql_dir/bin:$PATH" >>/root/.bash_profile

source /root/.bash_profile


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章