MySQL Multi-instance installation

Source: Internet
Author: User

Preface : The previous article has introduced a single instance of the installation, we continue to do MySQL multi-instance installation, we utilize multiple configuration files, multiple boot file management multi-instance


First, install the dependency package
Yum install ncurses-devel libaio-devel gcc gcc-c++ cmake perl

Download the MySQL installation package, mysql-5.5 the installation package, and unzip the installation package

TAR-ZXVF mysql-5.5.32.tar.gz CD mysql-5.5.32

Compiling the installation

Cmake-dcmake_install_prefix=/usr/local/mysql-dwith_innobase_storage_engine=1-dwith_federated_storage_engine=1- dwith_blackhole_storage_engine=1 \-dwith_example_storage_engine=1 \-dwith_partition_storage_engine=1 \-DWITH_FAST _mutexes=1 \-dwith_zlib=bundled \-denabled_local_infile=1 \-dwith_readline=1-dwith_embedded_server=1-dmysql_unix_ Addr=/usr/local/mysql/mysql.sock-denabled_local_infile=on-ddefault_charset=utf8-ddefault_collation=utf8_ General_ci-dwith_debug=0make && make Install
Second, configure user rights

Set up MySQL users and groups

Groupadd mysqluseradd-g MySQL MySQL

New MySQL installation directory and data file directory

Mkdir-p/usr/local/mysql mkdir-p/data/3306mkdir-p/data/3307

Modify Directory Owners and groups

Chown-r mysql:mysql/usr/local/mysqlchown-r mysql:mysql/data/3306chown-r mysql:mysql/data/3307
Third, initialize the database, configure the configuration file, configure the boot file, etc.
/usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/data/3306/data--user=mysql/usr/ local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/data/3307/data--user=mysql

Create multiple configuration files

vim  /data/3306/my.cnf[client] port = 3306 socket = /data/3306/ Mysql.sock [mysqld] port = 3306 socket = /data/3306/mysql.sock basedir  = /usr/local/mysql datadir = /data/3306/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 skip-name-resolve  log-bin=mysql-bin binlog_format=mixed max_binlog_size = 500m server-id =  1 [mysqld_safe] log-error=/data/3306/ilanni.err pid-file=/data/3306/ilanni.pid [ Mysqldump] quick max_allowed_packet = 16m [mysql] no-auto-rehash [myisamchk ] key_buffer_size  = 20m sort_buffer_size = 20m read_buffer = 2m write_buffer =  2m [mysqlhotcopy] interactive-timeout

Copy one to 3307, and 3306 in the file is replaced by 3307.

Cp/data/3306/my.cnf/data/3307/my.cnfsed-i ' s/3306/3307/g '/data/3307/my.cnf

Create a MySQL service startup script

Vim /data/3306/mysqld#!/bin/bashmysql_port=3306mysql_username= "admin" mysql_password= "password" function_ Start_mysql () {printf  "starting mysql...\n"/bin/sh /usr/local/mysql/bin/mysqld_safe -- Defaults-file=/data/${mysql_port}/my.cnf 2>&1 > /dev/null &}function_stop_ MySQL () {printf  "stoping mysql...\n"/usr/local/mysql/bin/mysqladmin -u ${mysql_username}  -p${mysql_password} -s /data/${mysql_port}/mysql.sock shutdown}function_restart_mysql () { printf  "restarting mysql...\n" Function_stop_mysqlfunction_start_mysql}function_kill_mysql () {Kill  -9 $ (ps -ef | grep  ' Bin/mysqld_safe '  | grep ${mysql_port} |  awk  ' {printf $2} ') kill -9 $ (ps -ef | grep  ' libexec/mysqld '   | grep ${mysql_port} | awk  ' {printf $2} ')}case $1 instart) function_ Start_mysql;; Stop) Function_stoP_mysql;; Kill) Function_kill_mysql;; restart) Function_stop_mysqlfunction_start_mysql;; *) echo  "Usage: /data/${mysql_port}/mysqld {start|stop|restart|kill}";; Esac

Copy to 33,071 startup scripts, change the 3306 inside to 3307, and give the startup permission

Cp/data/3306/mysqld/data/3307/mysqldsed-i ' s/3306/3307/g '/data/3307/mysqld chmod +x/data/3306/mysqld chmod +x/data/ 3307/mysqld

Modify the/etc/profile file to add the path at the end

Path=/usr/local/mysql/bin: $PATHexport PATH

Save changes to make the configuration take effect immediately

Source/etc/profile
Four, start the database and log in
/data/3306/mysqld start/data/3307/mysqld startmysql-uroot-p-s/data/3306/mysql.sockmysql-uroot-p-s/data/3307/ Mysql.sock


This article is from the "Database learning process" blog, so be sure to keep this source http://yuemu.blog.51cto.com/10688235/1868201

MySQL Multi-instance installation

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.