mysql-5.6.x和mysql-5.7.x二进制安装

#!/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  $1}'  | grep  mysql`

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

uflag=`cat  /etc/passwd  |awk -F':'  '{print  $1}'  | 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-devel bison-devel bison build-essential libncurses5-dev cmake openssl  openssl-devel >/dev/null

}

function  check_datadir(){

[ -f "${MDIR}" ] && echo -e "\e[1;35m目录被锁定,请确保没有安装过mysql服务\e[0m" && exit 1

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

#[ ! -d "$MDIR/data" ] && mkdir -p "$MDIR/data"  二进制的mysql解压出来就有一个data目录的

chown  -R mysql.mysql   $MDIR

}

function menu(){

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

cat<<EOF

Please choose  mysql  version  which  you 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 that you  want to install:" flag

read -p  "please enter mysql root password that you want to set:" mysql_password

}

function  mysql_download(){

case $flag  in

1)

VERSION="mysql-5.6.39"

echo -e "\e[1;34m${VERSION} binary will 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 will 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/local/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  #不给权限,初始化报错 如下:

#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设置密码方法。和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/local/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

#初始化数据库,登录密码是空的

/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



原文地址:http://blog.51cto.com/12262646/2090862

时间: 2024-10-01 10:24:09

mysql-5.6.x和mysql-5.7.x二进制安装的相关文章

mysql 5.7.12二进制安装

1.my.cnf配置文件参数:vim /etc/my.cnf [client] port = 3306 socket = /tmp/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /aliyun/server/mysql-5.7.12/ datadir = /data/mysql/data/ open_files_limit = 1024

关于centos7如何二进制安装mysql,详细步骤!

第一步:首先在mariadb官网下载mariadb编译好的二进制压缩包https://downloads.mariadb.org/ 第二步:解压下载好的mariadb压缩包,由于下载好的是别人编译好的二进制压缩包,所以解压路径是有规定的必须在 "/usr/local/" 下,若是自己源码编译可以自行选择解压目录! tar xvf mariadb-102.23-linux-x86_64.tar.gz -C /usr/local/ · 第三步:由于解压好的文件夹(mariadb-10.2.

MySQL之MySQL:prompt 设置 -登陆MySQL显示用户名和主机以及当前数据库

是开始但愿不是结束,是起点但愿不是终点 今天在做MySQL练习过程中,突然发现,登陆mysql后,命令行不能显示用户名和主机信息,同时呢,想查看数据库信息还需要查看select datebase()命令查看,特别不方便,因此特别查看了mysql的相关资料,每次通过客户端登陆怎么才能显示这些信息呢?其实MySQL的相关设置都在配置文件my.cnf中可以设置.因此就去看my.cnf文件,之前就使用下,没有细心看.my.cnf配置文件中两大部分:[client]和[mysqld],前者是客户端的配置参

centos6.5二进制安装mysql

[[email protected] ~]# yum install libaio-devel -y    #安装共享库 [[email protected] ~]# wget http://mirrors.sohu.com/mysql/My ... ux2.6-x86_64.tar.gz #下载MySQL二进制包 [[email protected] ~]# tar xf mysql-5.5.48-linux2.6-x86_64.tar.gz #解压二进制包 [[email protected

Mysql二进制安装

Mysql安装 安装步骤 1.新建用户 groupadd mysql useradd -r -g mysql mysql cd /usr/local/----------------------------注意路径 chown -R mysql:mysql  mysql chmod -R 775  mysql 2.安装依赖包 yum install libai* -y yum install ncurses-devel -y yum -y install bison yum install zl

MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限

1.新建用户 //登录MYSQL@>mysql -u root -p@>密码//创建用户mysql> insert into mysql.user(Host,User,Password) values('localhost','jeecn',password('jeecn'));//刷新系统权限表mysql>flush privileges;这样就创建了一个名为:jeecn  密码为:jeecn  的用户. //退出后登录一下mysql>exit;@>mysql -u

MySQL最新版本 MySQL5.7.11 批量自动化一键式安装

以前都喜欢了源码安装MySQL,总觉得源码是高大上的事情,不过源码也需要时间,特别是make的时候,如果磁盘和cpu差的话,时间很长很长,在虚拟机上安装mysql尤其甚慢了. 现在业务发展了,开始在云上部署了,需要经常安装mysql,有的时候一次部署很多台,如果还是源码安装一个个去执行,效率就比较差了,所以准备采用更快效率的二进制来实现一键式自动化安装mysql. 1,mysql二进制安装包下载地址 下载地址:http://download.csdn.net/detail/mchdba/9488

mysql二进制安装启动的问题

二进制安装后,启动时出现问题(mysql安装在/application/msyql下): [[email protected] bin]# /etc/init.d/mysqld startStarting MySQL.170320 22:21:51 mysqld_safe The file /usr/local/mysql/bin/mysqlddoes not exist or is not executable. Please cd to the mysql installationdirec

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了 ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ---------------------------------------------- Fedora8启动mysql 报错:ERROR 2002 (HY000): Can’t connect

mysql二进制安装,升级,多实例部署

目标 理解线上部署考虑的因素 学会编译安装以及二进制安装mysql 学会升级mysql 学会多实例部署mysql数据库 学会合理部署mysql线上库 考虑因素: 版本选择,5.1,5.5还是5.6? 分支选择,官方社区版?percona server?mariadb? 推荐官方版,简单易上手 安装方式,包安装?二进制包安装?源码安装? 线上推荐二进制包安装 路径配置,参数配置(尽量模板化,标准化) 一个实例多个库,or多个实例单个库? 二进制安装mysql 下载软件安装包 解压放到指定目录(比如