mysql-5.7.20 Source installation + Multi-instance + master-slave replication

Source: Internet
Author: User

Version: MySQL-5.7.20


1. Replace the Yum source

Wget-o/etc/yum.repos.d/eprl.repo Http://mirrors.aliyun.com/repo/epel-6.repo


2, installation CMake

Tar XF cmake-3.0.0.tar.gz

CD cmake-3.0.0

./bootstrap

Make

Make install


2. Install boost

TAR-ZXVF boost_1_59_0.tar.gz-c/usr/local/


3. Create the installation directory and the required files

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. Install dependent packages

Yum-y Install ncurses ncurses-devel Bison Libgcrypt Perl


5. Create user

Useradd mysql-s/sbin/nologin-m


6. Unzip and install

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. Create a soft connection

Ln-s/application/mysql-5.7.22/application/mysql


8. Add Environment variables

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

Source/etc/profile


9. Initialization

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


10. Copy Start command

/BIN/CP Support-files/mysql.server/etc/init.d/mysqld


11, modify the/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. Modify the owner of the MySQL installation directory

Chown-r Mysql.mysql/application/mysql


13. Start

/etc/init.a/mysqld start


14. Change the password

Mysqladmin-uroot-s/application/mysql/mysql.sock password ' 123456 '


Configure multiple instances

1. Turn off MySQL

/etc/init.d/mysqld stop


2. Create the required directories and documents

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

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

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

Chown-r mysql.mysql/data/


3. Initialization

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


4. Assigning a separate configuration file

#配置文件优先级,/etc/and Basedir directories do not exist MY.CNF configuration files

/ETC/MY.CNF >basedir/my.cnf >datadir/my.cnf


Vim/data/3306/my.cnf

#可自由选择, the parameters are from the network

[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. Start test

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


6. mysql Startup script

#!/bin/bash

port=3306

Mysql_user= "Root"

Mysql_pwd= "$"

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 $ in

Start

Start

;;

Stop

Stop

;;

Restart

Restart

;;

*)

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

Esac

$*


mysql-5.7.20 Source installation + Multi-instance + master-slave replication

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.