mysql 一键脚本_mysql一键安装脚本

GROUP=mysql

USER=mysql

MYSQL_HOME=/usr/local/mysql

MYSQL_DATA_HOME=/data/mysql/data

D_VERSION="mysql-boost-5.7.25"

MYSQL_VERSION="mysql-5.7.25"

DOWNLOAD_PATH="/usr/local/src"

echo "=================================start install mysql==================================="

if [ $(id -u) != "0" ];then

echo "Error: You must be root to run this script!"

exit 1

fi

if [ -z $(cat /etc/group|awk -F: ‘{print $1}‘| grep -w "$GROUP") ]

then

groupadd $GROUP

if(( $? == 0 ))

then

echo "group $GROUP add sucessfully!"

fi

else

echo "$GROUP is exsits"

fi

if [ -z $(cat /etc/passwd|awk -F: ‘{print $1}‘| grep -w "$USER") ]

then

adduser -g $GROUP $USER

if (( $? == 0 ))

then

echo "user $USER add sucessfully!"

fi

else

echo "$USER is exsits"

fi

for i in make gcc-c++ bison-devel ncurses-devel perl perl-devel wget cmake bzip2 bzip2-devel bzip2-libs python-devel

do

yum -y install $i

done >/dev/null

echo "==================================downloading mysql===================================="

rm -rf ${DOWNLOAD_PATH}/mysql*

wget https://cdn.mysql.com//Downloads/MySQL-5.7/${D_VERSION}.tar.gz -P ${DOWNLOAD_PATH} >/dev/null

if(( $? == 0 ))

then

echo "MySQL DownLoad sucessfully!"

else

echo "MySQL DownLoad failed!"

exit 1

fi

cd ${DOWNLOAD_PATH}

echo "=================================unpackaging mysql====================================="

tar xzvf ${D_VERSION}.tar.gz >/dev/null

cd ${MYSQL_VERSION}

if [ -s /etc/my.cnf ]; then

mv /etc/my.cnf /etc/my.cnf.date +%Y%m%d%H%M%S.bak

fi

cat << EOF >/etc/my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/data/mysql/data

port=3306

bind-address=0.0.0.0

socket=/usr/local/mysql/mysql.sock

lower_case_table_names=1

slow_query_log=1

long_query_time=1

max_connections=1000

gtid_mode=ON

enforce-gtid-consistency=true

log_error_verbosity=2

max_connections=500

back_log=200

open_files_limit=60000

table_open_cache=2000

thread_cache_size=400

server-id=1

lower_case_table_names=1

skip-external-locking

local_infile=0

character-set-server=utf8

collation-server=utf8_general_ci

default-storage-engine=InnoDB

transaction_isolation=READ-COMMITTED

autocommit=1

sql_mode=TRADITIONAL

max_allowed_packet=256M

show_compatibility_56=1

interactive_timeout=7200

wait_timeout=7200

user=mysql

early-plugin-load=‘‘

skip-ssl

explicit_defaults_for_timestamp=1

symbolic-links=0

query_cache_type=0

query_cache_size=0

gtid_mode=ON

enforce-gtid-consistency

innodb_undo_tablespaces=16

innodb_max_undo_log_size=1G

innodb_undo_logs=128

innodb_undo_log_truncate=1

innodb_purge_rseg_truncate_frequency=128

innodb_data_file_path=ibdata1:10M:autoextend

innodb_autoextend_increment=128

innodb_file_per_table=1

innodb_log_files_in_group=4

innodb_log_file_size=128M

innodb_log_buffer_size=8M

innodb_flush_log_at_trx_commit=1

innodb_buffer_pool_size=4G

innodb_buffer_pool_instances=4

innodb_old_blocks_pct=40

innodb_max_dirty_pages_pct=90

innodb_io_capacity=200

innodb_io_capacity_max=2000

innodb_doublewrite=1

sort_buffer_size=8M

join_buffer_size=8M

innodb_lock_wait_timeout=30

innodb_thread_concurrency=4

tmp_table_size=256M

max_heap_table_size=128M

innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:4G

log_timestamps=SYSTEM

innodb_stats_auto_recalc=1

innodb_stats_persistent=1

log_output=‘TABLE‘

slow_query_log=0

long_query_time=1

min_examined_row_limit=0

log_queries_not_using_indexes=0

log_throttle_queries_not_using_indexes=20

log_slow_admin_statements=1

general_log=0

concurrent_insert=1

key_buffer_size=128M

read_buffer_size=2M

read_rnd_buffer_size=8M

myisam_sort_buffer_size=64M

log_slave_updates=0

relay_log_purge = 1

relay_log_recovery = 1

master_info_repository=TABLE

relay_log_info_repository=TABLE

slave_parallel_workers=2

slave_parallel_type=LOGICAL_CLOCK

EOF

echo "==========================configuring mysql,please wait================================"

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/data/mysql/db \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DENABLE_DOWNLOADS=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_DEBUG=0 \

-DMYSQL_MAINTAINER_MODE=0 \

-DWITH_SSL:STRING=bundled \

-DWITH_ZLIB:STRING=bundled \

-DWITH_BOOST=boost >/dev/null

echo "==========================make mysql, pleas,please wait================================"

make && make install

if [ $? -ne 0 ];then

echo "make failed ,please check it out!"

exit 1

fi

mkdir -p "${MYSQL_DATA_HOME}"

$MYSQL_HOME/bin/mysqld --initialize-insecure --user=$USER

chown -R mysql:mysql $MYSQL_HOME

chown -R mysql:mysql $MYSQL_DATA_HOME

cp $MYSQL_HOME/support-files/mysql.server /etc/init.d/mysql

echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile

source /etc/profile

/etc/init.d/mysql start

echo "==========================Mysql installation completed================================"

exit 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值