码迷,mamicode.com
首页 > 数据库 > 详细

mysql-5.7.20源码安装 + 多实例 + 主从复制

时间:2018-04-28 19:26:37      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:mysql源码安装

版本:MySQL-5.7.20 


1、更换yum源

wget -O /etc/yum.repos.d/eprl.repo http://mirrors.aliyun.com/repo/epel-6.repo


2、安装cmake

tar xf cmake-3.0.0.tar.gz

cd cmake-3.0.0

./bootstrap

make

make install


2、安装boost

tar -zxvf boost_1_59_0.tar.gz -C /usr/local/


3、创建安装目录及所需要文件

mkdir -p /application/mysql-5.7.22/{data,logs,pids}

touch /application/mysql-5.7.22/logs/mysqld.log

touch /application/mysql-5.7.22/pids/mysqld.pid


4、安装依赖软件包

yum -y install ncurses ncurses-devel bison libgcrypt perl


5、创建用户

useradd mysql -s /sbin/nologin -M


6、解压并安装

tar xf mysql-5.7.22.tar.gz

cd mysql-5.7.22

cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.22 -DMYSQL_DATADIR=/application/mysql-5.7.22/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

make

make install


7、创建软连接

ln -s /application/mysql-5.7.22 /application/mysql


8、添加环境变量

echo "PATH=/application/mysql/bin:/application/mysql/lib:$PATH" >>/etc/profile

source /etc/profile


9、初始化

mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data


10、复制启动命令

/bin/cp support-files/mysql.server /etc/init.d/mysqld


11、修改/etc/my.cnf

[mysqld]

datadir=/application/mysql/data

socket=/application/mysql/mysql.sock


[mysqld_safe]

log-error=/application/mysql/logs/mysqld.log

pid-file=/application/mysql/pids/mysqld.pid


symbolic-links=0


[client]

default-character-set=utf8

socket=/application/mysql/mysql.sock


[mysql]

default-character-set=utf8

socket=/application/mysql/mysql.sock


12、修改mysql安装目录的属主

chown -R mysql.mysql /application/mysql


13、启动

/etc/init.a/mysqld start


14、修改密码

mysqladmin -uroot -S /application/mysql/mysql.sock password '123456'


《配置多实例》

1、关闭mysql

/etc/init.d/mysqld stop


2、创建所所需要目录及文件

mkdir -p /data/{3306,3307}/data

touch /data/{3306,3307}/mysql.pid

touch /data/{3306,3307}/error.log

chown -R mysql.mysql /data/


3、初始化

mysqld --no-defaults --initialize-insecure --basedir=/application/mysql-5.7.22 --datadir=/data/3306/data/ --user=mysql --explicit_defaults_for_timestamp


4、分配独立配置文件

#配置文件优先级,/etc/与basedir目录下不要存在my.cnf配置文件

/etc/my.cnf >basedir/my.cnf >datadir/my.cnf


vim /data/3306/my.cnf     

#可自由选择,参数来自网络

[mysqld]

port= 3306

socket= /data/3306/mysql.sock

datadir= /data/3306/data

skip-external-locking

key_buffer_size = 32M

max_allowed_packet = 1M

table_open_cache = 128

sort_buffer_size = 768K

net_buffer_length = 8K

read_buffer_size = 768K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

thread_cache_size = 16

query_cache_size = 16M

tmp_table_size = 32M

log-error= /data/3306/error.log

pid-file= /data/3306/mysql.pid

explicit_defaults_for_timestamp = true

max_connections = 100

max_connect_errors = 5

open_files_limit = 65535

log-bin=mysql-bin

binlog_format=mixed

server-id = 1

expire_logs_days = 10

early-plugin-load = ""

default_storage_engine = InnoDB

innodb_data_home_dir = /data/3306/data

innodb_data_file_path = ibdata1:10M:autoextend

innodb_log_group_home_dir = /data/3306/data

innodb_buffer_pool_size = 128M

innodb_log_file_size = 32M

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

[myisamchk]

key_buffer_size = 32M

sort_buffer_size = 768K

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout


5、启动测试

mysqld_safe --defaults-file=/data/3306/my.cnf


6、mysql启动脚本

#!/bin/bash

port=3306

mysql_user="root"

mysql_pwd="$2"

CmdPath="/application/mysql/bin"

mysql_sock="/data/${port}/mysql.sock"


function start () {

if [ ! -e "${mysql_sock}" ];then

        printf "Starting MySQL...\n"

        /bin/bash ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &

    else

        printf "MySQL is running...\n"

        exit

fi

}


function stop () {

if [ ! -e "$mysql_sock" ];then

        printf "MySQL is stoping...\n"

        exit

    else

        printf "Stoping MySQL..."

        ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown

fi

}

function restart () {

    printf "Restarting MySQL...\n"

    stop

    sleep 2

    start

}


case $1 in

    start)

        start

        ;;

    stop)

        stop

        ;;

    restart)

        restart

        ;;

    *)

        printf "Usage: /data/${port}/mysql{start|stop|restart}\n"

esac

$*


mysql-5.7.20源码安装 + 多实例 + 主从复制

标签:mysql源码安装

原文地址:http://blog.51cto.com/12098963/2108968

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!