mysql-5.6.x and mysql-5.7.x binary installation

Source: Internet
Author: User
Tags mixed mysql version openssl rehash

#!/bin/bash

#__Author__: Allen_jol at 2018-03-21 13:52:13

#Description: Install mysql-5.6.39 or mysql-5.7.21 binary for CentOS 6.x


cpuinfo= ' Cat/proc/cpuinfo | GREP-C Processor '

Dir= "/USR/LOCAL/SRC"

Mdir= "/usr/local/mysql"

Datadir= "$MDIR/data"

Mysql56_bin_source= "Mysql-5.6.39-linux-glibc2.12-x86_64"

Mysql56_down_url= "Https://cdn.mysql.com//downloads/mysql-5.6/${mysql56_bin_source}.tar.gz"

Mysql57_bin_source= "Mysql-5.7.21-linux-glibc2.12-x86_64"

Mysql57_down_url= "Https://cdn.mysql.com//downloads/mysql-5.7/${mysql57_bin_source}.tar.gz"


#cpuinfo =${grep "Processor"/proc/cpuinfo | wc-l}

function Checkroot () {

If [$UID-ne 0];then

ECHO-E "\e[1;35mplease Login as root\e[0m"

Exit 1

Fi

}

function Create_user_mysql () {

gflag= ' Cat/etc/group |awk-f ': ' {print $} ' | grep MySQL '

[[$gflag! = ""]] && echo-e "\e[1;35mgroup ' MySQL ' already exists\e[0m" | | Groupadd MySQL

uflag= ' cat/etc/passwd |awk-f ': ' {print $} ' | grep MySQL '

[[$uflag! = ""]] && echo-e "\e[1;35muser ' MySQL ' already exists\e[0m" | | Useradd-r mysql-g mysql-s/sbin/nologin

}

function Msgbox () {

If [$?-ne 0];then

Echo-e "\e[1;35merror,please check\e[0m"

Exit 1

Fi

}

function Install_required_packages () {

Echo-e "Install required packages,please wait...\t Or you can press \e[5;35m[ctrl+c]\e[0m to exit."

Yum-y install wget gcc-c++ numactl autoconf automake libaio-devel zlib zlib-devel ncurses ncurses-devel Tcp_wrappers-dev El Bison-devel Bison build-essential libncurses5-dev cmake OpenSSL openssl-devel >/dev/null

}

function Check_datadir () {

[-F "${mdir}"] && echo-e "\e[1;35m directory is locked, make sure the MySQL service is not installed \e[0m" && exit 1

[!-D "$MDIR"] && mkdir-p $MDIR

#[!-d "$MDIR/data"] && mkdir-p "$MDIR/data" binary MySQL is extracted with a data directory

Chown-r Mysql.mysql $MDIR

}

Function menu () {

Echo-e "\e[1;34m**************************************************************\e[0m"

Cat<<eof

Please choose MySQL version which your want to install:

1:mysql-binary-5.6.39

2:mysql-binary-5.7.21

Eof

Echo-e "\e[1;34m**************************************************************\e[0m"

}

function Mysql_version () {

Read-p "Please choose MySQL version so want to install:" Flag

Read-p "Please enter MySQL root password this want to set:" Mysql_password

}

function Mysql_download () {

Case $flag in

1)

version= "mysql-5.6.39"

Echo-e "\e[1;34m${version} binary would be installed\e[0m"

[-F "${dir}/${mysql56_bin_source}.tar.gz"] && CD ${dir} && rm-f "${dir}/${mysql56_bin_source}.tar.gz"

#[-F "${dir}/${mysql56_bin_source}/"] && CD ${dir} && rm-f "${dir}/${mysql56_bin_source}/"

[!-F "${dir}/${mysql56_bin_source}.tar.gz"] && CD ${dir}

Nettest= ' ping-c 1 www.baidu.com >>/dev/null '

If [$?-eq 0];then

echo-e "\e[1;34mdownload ${version} now,please wait...\e[0m"

wget-c ${mysql56_down_url}

Else

echo-e "\e[1;35mnetwork is error,please check first.\e[0m"

Exit 1

Fi

;;

2)

version= "mysql-5.7.21"

Echo-e "\e[1;34m${version} binary would be installed.\e[0m"

[-F "${dir}/${mysql57_bin_source}.tar.gz"] && CD ${dir} && rm-f "${dir}/${mysql57_bin_source}.tar.gz"

[-F "${dir}/${mysql57_bin_source}/"] && CD ${dir} && rm-f "${dir}/${mysql57_bin_source}/"

[!-F "${dir}/${mysql57_bin_source}.tar.gz"] && CD ${dir}

Nettest= ' ping-c 1 www.baidu.com >>/dev/null '

If [$?-eq 0];then

echo-e "\e[1;34mdownload ${version} now,please wait...\e[0m"

wget-c ${mysql57_down_url}

Else

echo-e "\e[1;35mnetwork is error,please check first.\e[0m"

Exit 1

Fi

;;

*)

ECHO-E "\e[1;35mplease input number 1 or 2,other is not valid\e[0m"

Mysql_version

Mysql_download

Esac

}


function Mysql_install () {

Case $VERSION in

"mysql-5.6.39")

Echo-e "\e[1;34mconfig mysql,please wait...\e[0m"

CD ${dir} && tar zxf ${mysql56_bin_source}.tar.gz && cd ${mysql56_bin_source}/&& \mv./*/usr/loc Al/mysql

Mkdir-p/usr/local/mysql/logs && chown-r mysql.mysql/usr/local/mysql

[$?-eq 0] && echo "MySQL install OK, the next step is init mysql." | | ECHO-E "\e[1;35mmysql install error, please check\e[0m"

[-F "/etc/my.cnf"] && \mv/etc/my.cnf/etc/my.cnf.bak

Cat >/etc/my.cnf<<eof

[Client]

#password = Your_password

Port = 3306

Socket =/tmp/mysql.sock


# The MySQL server

[Mysqld]

# Basic

Relay_log_purge = 0

user = MySQL

Basedir =/usr/local/mysql

DataDir =/usr/local/mysql/data

Tmpdir =/usr/local/mysql

Log-bin =/usr/local/mysql/data/mysql-bin

Socket =/tmp/mysql.sock

Port = 3306

Server-id = 1

Relay_log_purge = 0

Binlog_format = row

Binlog_cache_size = 1M

Log-error =/usr/local/mysql/logs/error.log

Slow-query-log-file =/usr/local/mysql/logs/slow.log

Pid-file =/usr/local/mysql/mysqld.pid


Skip-external-locking

Skip-name-resolve

#skip-networking

Log-slave-updates

Binlog_format = Mixed

Max_binlog_size = 128M

Expire_logs_days = 10


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

# for Percona 5.6

#extra_port = 3345

Gtid-mode = On

Enforce_gtid_consistency

#thread_handling =pool-of-threads

#thread_pool_oversubscribe =8

Explicit_defaults_for_timestamp


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

Character-set-server = UTF8

Slow-query-log

Binlog_format = row

Max_binlog_size = 128M

Binlog_cache_size = 1M

Expire-logs-days = 5

Back_log = 500

Long_query_time = 1

Max_connections = 1100

max_user_connections = 1000

max_connect_errors = 1000

Wait_timeout = 100

Interactive_timeout = 100

Connect_timeout = 20

Slave-net-timeout = 30

Max-relay-log-size = 256M

Relay-log = Relay-bin

Transaction_isolation = read-committed

Performance_schema = 0

#myisam_recover

Key_buffer_size = 64M

Max_allowed_packet = 16M

#table_cache = 3096

Table_open_cache = 6144

Table_definition_cache = 4096

Sort_buffer_size = 128K

Read_buffer_size = 1M

Read_rnd_buffer_size = 1M

Join_buffer_size = 128K

Myisam_sort_buffer_size = 32M

Tmp_table_size = 32M

Max_heap_table_size = 64M

Query_cache_type = 0

Query_cache_size = 0

Bulk_insert_buffer_size = 32M

Thread_cache_size = 64

#thread_concurrency = 32

Thread_stack = 192K

Skip-slave-start

# InnoDB

Innodb_data_home_dir =/usr/local/mysql/data

Innodb_log_group_home_dir =/usr/local/mysql/data

Innodb_data_file_path = Ibdata1:10m:autoextend

Innodb_buffer_pool_size = 500M

Innodb_buffer_pool_instances = 8

#innodb_additional_mem_pool_size = 16M

Innodb_log_file_size = 200M

Innodb_log_buffer_size = 16M

Innodb_log_files_in_group = 3

Innodb_flush_log_at_trx_commit = 0

Innodb_lock_wait_timeout = 10

Innodb_sync_spin_loops = 40

innodb_max_dirty_pages_pct = 90

Innodb_support_xa = 0

innodb_thread_concurrency = 0

Innodb_thread_sleep_delay = 500

#innodb_file_io_threads = 4

Innodb_concurrency_tickets = 1000

Log_bin_trust_function_creators = 1

Innodb_flush_method = O_direct

Innodb_file_per_table

Innodb_read_io_threads = 16

Innodb_write_io_threads = 16

innodb_io_capacity = 2000

Innodb_file_format = Barracuda

Innodb_purge_threads = 1

Innodb_purge_batch_size = 32

innodb_old_blocks_pct = 75

Innodb_change_buffering = All

Innodb_stats_on_metadata = OFF

[Mysqldump]

Quick

Max_allowed_packet = 128M

#myisam_max_sort_file_size = 10G

[MySQL]

No-auto-rehash

Max_allowed_packet = 128M

prompt = '-product-[\[email protected]\h][\d]> '

Default_character_set = UTF8

[Myisamchk]

Key_buffer_size = 64M

Sort_buffer_size = 10M

Read_buffer = 2M

Write_buffer = 2M

[Mysqld_safe]

Log-error =/usr/local/mysql/logs/error.log

Pid-file=/usr/local/mysql/mysqld.pid


[Mysqlhotcopy]

Interactive-timeout

Eof

Echo-e "\e[1;34minit MySQL now,please wait...\e[0m"

chmod 777/usr/local/mysql #不给权限, the initial error is as follows:

#Can ' t create/write to file '/usr/local/mysql/ibigikvs ' (Errcode:13-permission denied)

/usr/local/mysql/scripts/mysql_install_db--basedir=${mdir}--datadir=${datadir}--user=mysql >/dev/null 2> &1

Echo ' Export path= $PATH:/usr/local/mysql/bin ' >>/etc/profile && Echo '/etc/init.d/mysqld start ' >> /etc/rc.d/rc.local

Source/etc/profile

\CP ${mdir}/support-files/mysql.server/etc/init.d/mysqld && chmod +x/etc/init.d/mysqld && chkconfig Mysqld on

#加载动态库

Cat >/etc/ld.so.conf.d/mysql.conf<<eof

/usr/local/mysql/lib

/usr/local/lib

Eof

Ldconfig

Ln-sf/usr/local/mysql/bin/mysql/usr/bin/mysql

Ln-sf/usr/local/mysql/bin/mysqldump/usr/bin/mysqldump

Ln-sf/usr/local/mysql/bin/myisamchk/usr/bin/myisamchk

Ln-sf/usr/local/mysql/bin/mysqld_safe/usr/bin/mysqld_safe

Ln-sf/usr/local/mysql/bin/mysqlcheck/usr/bin/mysqlcheck

#start MySQL

/etc/init.d/mysqld start

#mysql -5.6.x to set the password method. Not the same as mysql-5.7.x.

/usr/local/mysql/bin/mysqladmin-uroot password ${mysql_password} >/dev/null 2>&1

;;

"mysql-5.7.21")

Echo-e "\e[1;34mconfig mysql,please wait...\e[0m"

CD ${dir} && tar zxf ${mysql57_bin_source}.tar.gz && cd ${mysql57_bin_source}/&& \mv./*/usr/loc Al/mysql

Mkdir-p/usr/local/mysql/logs && chown-r mysql.mysql/usr/local/mysql

[$?-eq 0] && echo "MySQL install OK, the next step is init mysql." | | ECHO-E "\e[1;35mmysql install error, please check\e[0m"

[-F "/etc/my.cnf"] && \mv/etc/my.cnf/etc/my.cnf.bak

Cat >/etc/my.cnf <<eof

[Client]

#password = Your_password

Port = 3306

Socket =/tmp/mysql.sock

[Mysqld]

Port = 3306

Socket =/tmp/mysql.sock

Basedir =/usr/local/mysql

DataDir =/usr/local/mysql/data

Skip-external-locking

Key_buffer_size = 16M

Max_allowed_packet = 1M

Table_open_cache = 64

Sort_buffer_size = 512K

Net_buffer_length = 8K

Read_buffer_size = 256K

Read_rnd_buffer_size = 512K

Myisam_sort_buffer_size = 8M

Thread_cache_size = 8

Query_cache_size = 8M

Tmp_table_size = 16M

Performance_schema_max_table_instances = 500

Explicit_defaults_for_timestamp = True

#skip-networking

Max_connections = 500

max_connect_errors = 100

Open_files_limit = 65535

Log-bin=/usr/local/mysql/data/mysql-bin

Binlog_format=mixed

Server-id = 1

Expire_logs_days = 10

Early-plugin-load = ""

Default_storage_engine = InnoDB

innodb_file_per_table = 1

Innodb_data_home_dir =/usr/local/mysql/data

Innodb_data_file_path = Ibdata1:10m:autoextend

Innodb_log_group_home_dir =/usr/local/mysql/data

Innodb_buffer_pool_size = 16M

Innodb_log_file_size = 5M

Innodb_log_buffer_size = 8M

Innodb_flush_log_at_trx_commit = 1

Innodb_lock_wait_timeout = 50

[Mysqldump]

Quick

Max_allowed_packet = 16M

[MySQL]

No-auto-rehash

prompt = '-product-[\[email protected]\h][\d]> '

[Myisamchk]

Key_buffer_size = 20M

Sort_buffer_size = 20M

Read_buffer = 2M

Write_buffer = 2M

[Mysqlhotcopy]

Interactive-timeout

Eof

CD ${mdir} && mkdir-p ${mdir}/{data,logs}

Chown-r Mysql.mysql/usr/local/mysql

chmod 777/usr/local/mysql

#初始化数据库, the login password is empty

/usr/local/mysql/bin/mysqld--initialize-insecure--basedir=${mdir}--datadir=${datadir}--user=mysql >/dev/null 2>&1

Echo ' Export path= $PATH:/usr/local/mysql/bin ' >>/etc/profile && Echo '/etc/init.d/mysqld start ' >> /etc/rc.d/rc.local

Source/etc/profile

\CP ${mdir}/support-files/mysql.server/etc/init.d/mysqld && chmod +x/etc/init.d/mysqld && chkconfig Mysqld on

#加载动态库

Cat >/etc/ld.so.conf.d/mysql.conf<<eof

/usr/local/mysql/lib

/usr/local/lib

Eof

Ldconfig

Ln-sf/usr/local/mysql/bin/mysql/usr/bin/mysql

Ln-sf/usr/local/mysql/bin/mysqldump/usr/bin/mysqldump

Ln-sf/usr/local/mysql/bin/myisamchk/usr/bin/myisamchk

Ln-sf/usr/local/mysql/bin/mysqld_safe/usr/bin/mysqld_safe

Ln-sf/usr/local/mysql/bin/mysqlcheck/usr/bin/mysqlcheck

#start MySQL

/etc/init.d/mysqld start

#更改mysql登陆密码

/USR/LOCAL/MYSQL/BIN/MYSQL-E "Update mysql.user set Authentication_string=password (${mysql_password}) where user= ' Root ' and Host = ' localhost ';

/USR/LOCAL/MYSQL/BIN/MYSQL-E "alter user ' root ' @ ' localhost ' identified by ${mysql_password};"

/usr/local/mysql/bin/mysql-uroot-p${mysql_password}-E "flush privileges;"

;;

*)

echo "Mysql version error,please check" && exit 1

;;

Esac

}

Msgbox


function Mysql_check_status () {

NETSTAT-TUNLP | grep mysqld

If [$?-eq 0];then

mysql_version= ' Mysql-v '

Echo-e "MySQL start sucess,and mysql version is: \ n" "\e[1;35m${mysql_version}\e[0m"

Echo-e "Mysql root password is:\t \e[1;35m${mysql_password}\e[0m"

Else

Echo-e "\e[1;35mmysql start failed, please check\e[0m"

Exit 1;

Fi

}

function Main () {

Checkroot

Create_user_mysql

Install_required_packages

Check_datadir

Menu

Mysql_version

Mysql_download

Mysql_install

Mysql_check_status

}

Main



mysql-5.6.x and mysql-5.7.x binary installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.