Chinaunix首页 | 论坛 | 博客
  • 博客访问: 553937
  • 博文数量: 36
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1749
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-20 16:13
个人简介

中国科学院大学计算机硕士,曾在新浪爱彩数据库组带DBA团队,现居新加坡。wx: lihui_dba

文章分类

全部博文(36)

文章存档

2020年(2)

2019年(3)

2017年(7)

2016年(1)

2015年(7)

2014年(11)

2013年(5)

分类: Mysql/postgreSQL

2014-11-04 17:00:05

注:因官方MySQL下载较慢,请先自行上传mysql安装包至/usr/local/src目录

#!/bin/bash

#This shell script can be used to install mysql instances automatically
#Written by LiHui
#Version 1.0

#MySQL Install path 
Install_path=/usr/local/mysql

#MySQL Datadir
Datadir=/data0/mysqldata/3306/data

#Add MySQL user and group 
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql

#Install some packages 
yum -y install cmake gcc gcc-c++ autoconf automake zlib libxml ncurses-devel libmcrypt libtool bison

#本地上传,此部分注释
#downloading MySQL 
#echo "###Downloading MySQL###" 
cd /usr/local/src 
#wget 

#Install MySQL 
echo "###install MySQL###" 
tar -zxf /usr/local/src/mysql-5.5.24.tar.gz -C /usr/local/src/

cd /usr/local/src/mysql-5.5.24

cmake -DCMAKE_INSTALL_PREFIX=${Install_path} -DINSTALL_DATADIR=$Datadir -DWITH_SERVER_SUFFIX=lihui_edition -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_SSL=yes -DWITH_EMBEDDED_SERVER=1 -DWITH_PTHREAD=1 -DMYSQL_USER=mysql -DWITH_MYSQLD_LDFLAGS=-all-static -DWITH_INNOBASE_STORAGE_ENGINE=1 > /usr/home/mysql/mysql_setuplogs_cmake.log 2>&1

make > /usr/home/mysql/mysql_setuplogs_make.log 2>&1 && make install > /usr/home/mysql/mysql_setuplogs_makeinstall.log 2>&1

cd /usr/local/

chown -R mysql:mysql mysql

cp /usr/local/mysql/bin/mysql* /usr/bin/

#Create my.cnf

cat > /etc/my.cnf < [client]
port = 3306
socket = /data0/mysqldata/3306/mysql.sock
default-character-set = utf8
#Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /data0/mysqldata/3306/mysql.sock
pid-file = /data0/mysqldata/3306/mysql.pid
basedir = /usr/local/mysql
datadir = /data0/mysqldata/3306/data
tmpdir = /data0/mysqldata/3306/tmp
open_files_limit = 10240
server-id = 1423306
lower_case_table_names = 1
character_set_server = utf8
skip-name-resolve
max_connections = 500
max_connect_errors = 100000
max_allowed_packet = 512M
max_heap_table_size = 1024M
max_length_for_sort_data = 4096
back_log=100
interactive_timeout = 600
wait_timeout = 600
default_storage_engine = InnoDB
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
query_cache_size = 128M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
thread_cache_size = 300
table_open_cache = 1024
tmp_table_size = 256M
#*********** Logs related settings ***********
log_bin = /data0/mysqldata/3306/binlog/mysql-bin
binlog_format=row
binlog_cache_size=32m
max_binlog_cache_size=512m
max_binlog_size=512m
long_query_time = 1
log_output = FILE
log_error = /data0/mysqldata/3306/mysql-error.log
slow_query_log = 1
slow_query_log_file = /data0/mysqldata/3306/slow_statement.log
#log_queries_not_using_indexes
general_log = 0
general_log_file = /data0/mysqldata/3306/general_statement.log
expire-logs-days = 14
#*********** MyISAM Specific options ***********
key_buffer_size = 32M
bulk_insert_buffer_size = 32M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 2G
myisam_repair_threads = 1
myisam_recover
#*********** INNODB Specific options ***********
innodb_file_per_table
transaction-isolation = READ-COMMITTED
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_home_dir = /data0/mysqldata/3306/innodb_ts
innodb_data_file_path = ibdata1:16M:autoextend:max:8192M
innodb_thread_concurrency = 0
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_log_group_home_dir = /data0/mysqldata/3306/innodb_log
innodb_flush_log_at_trx_commit = 2
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 120
innodb_flush_method=O_DIRECT
[mysqldump]
quick
max_allowed_packet = 512M
[mysql]
no-auto-rehash
prompt="\\u@\\h \\R:\\m:\\s \\d> "
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 20M
read_buffer_size = 2M
write_buffer_size = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
EOF

#Init Database 
cd /data0 
mkdir -p mysqldata/3306 
cd mysqldata/3306
mkdir data binlog tmp innodb_ts innodb_log 
cd /data0
chown -R mysql:mysql mysqldata

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=${Install_path} --datadir=$Datadir --defaults-file=/etc/my.cnf

#Create mysqld(start|stop|restart|status) scripts 
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 
chmod +x /etc/init.d/mysqld

#Start mysqld service 
service mysqld start

#Test mysqld service 
service mysqld status | grep "SUCCESS" > /dev/null

if [ $? -eq 0 ];then

echo -e "MySQL install Done,Congratulation!"

fi

#create mysql root password
echo "Create password for user root.Please input new password:"
read password
mysqladmin -uroot password $password -S /data0/mysqldata/3306/mysql.sock

#delete empty password for user
mysql -uroot -p$password -S /data0/mysqldata/3306/mysql.sock mysql -e 'delete from user where password="";'
mysql -uroot -p$password -S /data0/mysqldata/3306/mysql.sock -e 'flush privileges;'
echo "ALL is OK!"

#Stop mysqld service 
service mysqld stop > /dev/null

阅读(1787) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~