Build a MySQL multi-instance environment in Linux _ MySQL

Source: Internet
Author: User
Tags localhost mysql
Set up MySQL multi-instance environment bitsCN.com in Linux

Build a MySQL multi-instance environment in Linux

Prerequisites: install cmake and gcc

Generally, gcc has been installed in linux. now cmake is installed.

[Root @ localhost workspace] # wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz

[Root @ localhost workspace] # tar xvf cmake-2.8.3.tar.gz

[Root @ localhost workspace] # cd cmake-2.8.3

[Root @ localhost workspace] #./configure

[Root @ localhost workspace] # make & make install

Download the mysql source code package

[Root @ localhost workspace] # wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.32.tar.gz

[Root @ localhost workspace] # tar xvf mysql-5.5.32.tar.gz

[Root @ localhost workspace] # cd mysql-5.5.32

Install the first MySQL database

(1) create the required File Directory

[Root @ localhost local] # cd/usr/local/

[Root @ localhost local] # mkdir mysql

[Root @ localhost local] # cd mysql/

[Root @ localhost mysql] # mkdir data

[Root @ localhost mysql] # mkdir etc

(2) configure MySQL source code compilation options

[Root @ localhost mysql-5.5.32] # cmake/

>-DCMAKE_INSTALL_PREFIX =/usr/local/mysql/

>-DMYSQL_DATADIR =/usr/local/mysql/data/

>-DSYSCONFDIR =/usr/local/mysql/etc/

>-DWITH_MYISAM_STORAGE_ENGINE = 1/

>-DWITH_INNOBASE_STORAGE_ENGINE = 1/

>-DWITH_MEMORY_STORAGE_ENGINE = 1/

>-DWITH_READLINE = 1/

>-DMYSQL_UNIX_ADDR =/tmp/mysqld. sock/

>-DMYSQL_TCP_PORT = 3306/

>-DENABLED_LOCAL_INFILE = 1/

>-DWITH_PARTITION_STORAGE_ENGINE = 1/

>-DEXTRA_CHARSETS = all/

>-DDEFAULT_CHARSET = utf8/

>-DDEFAULT_COLLATION = utf8_general_ci

(3) compile and install

[Root @ localhost mysql-5.5.32] # make & make install

(4) configure the first MySQL instance

[Root @ localhost mysql-5.5.32] # cd/usr/local/mysql

[Root @ localhost mysql] # chown-R mysql: mysql.

[Root @ localhost mysql] # cp support-files/my-medium.cnf/usr/local/mysql/etc/my. cnf

[Root @ localhost mysql] # vi/usr/local/mysql/etc/my. cnf

Add datadir =/usr/local/mysql/data

Default-storage-engine = MyISAM

[Root @ localhost mysql] # cd/usr/local/mysql/scripts/

[Root @ localhost scripts] #./mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data &

[Root @ localhost bin] # cd/usr/local/mysql/bin

[Root @ localhost bin] #./mysqld_safe -- user = root

[1] 28869

[Root @ localhost bin] #131016 20:07:13 mysqld_safe Logging to '/usr/local/mysql/data/localhost. localdomain. err '.

131016 20:07:14 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql/data

Check whether the service is successfully started.

[Root @ localhost bin] # netstat-tlnap | grep mysql

Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 29147/mysqld

Log on to MySQL and change the root user password

[Root @ localhost bin] #./mysqladmin-uroot password 'eisoo. com'

[Root @ localhost bin] #./mysql-uroot -peisoo.com

Welcome to the MySQL monitor. Commands end with; or/g.

Your MySQL connection id is 2

Server version: 5.5.32-log Source distribution

Copyright (c) 2000,201 3, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

Type 'help; 'or'/h' for help. type'/C' to clear the current input statement.

Mysql> exit

Install the second MySQL database

(1) clear configuration information

[Root @ localhost bin] # cd/workspace/mysql-5.5.32

[Root @ localhost mysql-5.5.32] # make clean

[Root @ localhost mysql-5.5.32] # rm-rf CMakeCache.txt

(2) create the required File Directory

[Root @ localhost mysql-5.5.32] # cd/usr/local/

[Root @ localhost local] # mkdir mysql3307

[Root @ localhost local] # cd mysql3307/

[Root @ localhost mysql3307] # mkdir data

[Root @ localhost mysql3307] # mkdir etc

(3) configure the compilation information for the second instance

[Root @ localhost bin] # cd/workspace/mysql-5.5.32

[Root @ localhost mysql-5.5.32] # cmake/

>-DCMAKE_INSTALL_PREFIX =/usr/local/mysql3307/

>-DMYSQL_DATADIR =/usr/local/mysql3307/data/

>-DSYSCONFDIR =/usr/local/mysql3307/etc/

>-DWITH_MYISAM_STORAGE_ENGINE = 1/

>-DWITH_INNOBASE_STORAGE_ENGINE = 1/

>-DWITH_MEMORY_STORAGE_ENGINE = 1/

>-DWITH_READLINE = 1/

>-DMYSQL_UNIX_ADDR =/tmp/mysqld3307.sock/

>-DMYSQL_TCP_PORT = 3307/

>-DENABLED_LOCAL_INFILE = 1/

>-DWITH_PARTITION_STORAGE_ENGINE = 1/

>-DEXTRA_CHARSETS = all/

>-DDEFAULT_CHARSET = utf8/

>-DDEFAULT_COLLATION = utf8_general_ci

(4) compile and install

[Root @ localhost mysql-5.5.32] # make & make install

(5) configure the second MySQL instance

[Root @ localhost mysql-5.5.32] # cd/usr/local/mysql3307

[Root @ localhost mysql3307] # chown-R mysql: mysql.

[Root @ localhost mysql3307] # cp support-files/my-medium.cnf/usr/local/mysql3307/etc/my. cnf

[Root @ localhost mysql3307] # vi/usr/local/mysql3307/etc/my. cnf

Add datadir =/usr/local/mysql3307/data

Default-storage-engine = MyISAM

[Root @ localhost mysql3307] # cd/usr/local/mysql3307/scripts/

[Root @ localhost scripts] #./mysql_install_db -- user = mysql -- basedir =/usr/local/mysql3307 -- datadir =/usr/local/mysql3307/data &

[Root @ localhost scripts] # cd/usr/local/mysql3307/bin

[Root @ localhost bin] #./mysqld_safe -- user = root

131016 20:40:27 mysqld_safe Logging to '/usr/local/mysql3307/data/localhost. localdomain. err '.

131016 20:40:27 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql3307/data

Check whether the service is successfully started.

[Root @ localhost bin] # netstat-tlnap | grep mysql

Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 29147/mysqld

Tcp 0 0 0.0.0.0: 3307 0.0.0.0: * LISTEN 7447/mysqld

Log on to MySQL and change the root user password

[Root @ localhost bin] #./mysqladmin-uroot password 'eisoo. com123'

[Root @ localhost bin] #./mysql-uroot-peisoo. com123

Welcome to the MySQL monitor. Commands end with; or/g.

Your MySQL connection id is 2

Server version: 5.5.32-log Source distribution

Copyright (c) 2000,201 3, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

Type 'help; 'or'/h' for help. type'/C' to clear the current input statement.

Mysql> exit

Add system environment variables

[Root @ localhost/] # vi/etc/profile

Add a row: export PATH =/usr/local/mysql/bin:/usr/local/mysql3307/bin: $ PATH

[Root @ localhost/] # source/etc/profile

[Root @ localhost/] # export $ PATH

Start different instances:

[Root @ localhost/] # mysqld_safe -- user = root -- port = 3306 -- socket =/tmp/mysqld. sock -- datadir =/usr/local/mysql/data &

[Root @ localhost/] # mysqld_safe -- user = root -- port = 3307 -- socket =/tmp/mysqld3307.sock -- datadir =/usr/local/mysql3307/data &

Log on to different instances:

[Root @ localhost/] # mysql-uroot -peisoo.com-S/tmp/mysqld. sock

[Root @ localhost/] # mysql-uroot-peisoo. com123-S/tmp/mysqld3307.sock

It is too troublesome to start. you can do this:

[Root @ localhost/] # cp/usr/local/mysql/support-files/mysql. server/etc/init. d/mysql3306

[Root @ localhost/] # cp/usr/local/mysql3307/support-files/mysql. server/etc/init. d/mysql3307

Add permissions to mysql users:

[Root @ localhost/] # chmod-R 755/usr/local/mysql/data

[Root @ localhost/] # chmod-R 755/usr/local/mysql/data

Start the corresponding services of the instance respectively:

[Root @ localhost tmp] # service mysql3306 start

Starting MySQL. [OK]

[Root @ localhost tmp] # service mysql3307 start

Starting MySQL. [OK]

View services:

[Root @ localhost tmp] # netstat-tlnap | grep mysql

Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 10759/mysqld

Tcp 0 0 0.0.0.0: 3307 0.0.0.0: * LISTEN 11097/mysqld

Add the service to the system service to enable it to automatically start upon startup.

[Root @ localhost/] # chkconfig -- add mysql3306

[Root @ localhost/] # chkconfig -- add mysql3307

BitsCN.com

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.