Home  >  Article  >  Database  >  Implementation steps to install two or more mysql on one server_MySQL

Implementation steps to install two or more mysql on one server_MySQL

WBOY
WBOYOriginal
2016-10-09 08:33:411094browse

How to install two or more mysql on one server? Below are the detailed steps, let’s learn together.

1. Environment

mysql package:

mysql-5.6.31.tar

mysql-5.5.32.tar

Operating system environment:

CentOS release 6.8 (Final)

2. System scale

/mysqlsoft Used to store various programs of mysql
/mysqlsoft/mysql1 Used to store the installation program of mysql-5.5.32.tar
/mysqlsoft/mysql2 Used to store the installation program of mysql-5.6.31.tar
/mysqlsoft/mysql1/mysql.sock
/mysqlsoft/mysql2/mysql.sock
/data Used to store data
/data/mysql1 Used to store data of mysql-5.5.32.
/data/mysql2 Used to store data of mysql-5.6.31.

3. Add users and directories

Add user

groupadd mysql

useradd mysql -g mysql

Create directory

mkdir /mysqlsoft

mkdir mysqlsoft/mysql1/ -pv

mkdir mysqlsoft/mysql2/ -pv

Create data directory

mkdir /data

mkdir /data/mysql1/ -pv

mkdir /data/mysql2/ -pv

Change permissions:

chown -R mysql:mysql mysqlsoft/mysql1

chown -R mysql:mysql mysqlsoft/mysql2

chown -R mysql:mysql /data/mysql1

chown -R mysql:mysql /data/mysql2

4. Compile mysql and install it

We need to install some tools before compiling and installing the source code

cmake,make,gcc,Perl, 

yum install cmake,make,gcc,Perl -y

4.1 mysql-5.5.32

cd mysqlsoft/mysql1/

tar -zxvf mysql-5.5.32.tar.gz

mkdir bootstarp

We compile the source code in the bootstarp directory

cmake .. -DCMAKE_INSTALL_PREFIX=/mysqlsoft/mysql1

-DMYSQL_DATADIR=/data/mysql1

-DSYSCONFDIR=/mysqlsoft/mysql1

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STORAGE_ENGINE=1

-DWITH_BLACKHOLE_STORAGE_ENGINE=1

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1

-DMYSQL_TCP_PORT=3301

-DMYSQL_UNIX_ADDR=/mysqlsoft/mysql1/mysql.sock

After compilation, we need to make and then make install

4.2 Work after installation

cd /mysqlsoft/mysql1

cp ./support-files/my-default.cnf my.cnf

Edit my.cnf to add configuration items

chown -R mysql .

chgrp -R mysql .

Initialize mysql:

scripts/mysql_install_db –user=mysql

Change permissions of mysql data directory

4.3 mysql-5.6.31

cd /mysqlsoft/mysql2

tar -zxvf mysql-5.6.31.tar.gz

mkdir bootstarp

We compile the source code in the bootstarp directory

cmake .. -DCMAKE_INSTALL_PREFIX=/mysqlsoft/mysql2

-DMYSQL_DATADIR=/data/mysql2

-DSYSCONFDIR=/mysqlsoft/mysql2

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STORAGE_ENGINE=1

-DWITH_BLACKHOLE_STORAGE_ENGINE=1

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1

-DMYSQL_TCP_PORT=3302

-DMYSQL_UNIX_ADDR=/mysqlsoft/mysql2/mysql.sock

After compilation, we need to make and then make install

4.4 Post-installation work

cd /mysqlsoft/mysql2

cp ./support-files/my-default.cnf my.cnf

Edit my.cnf to add configuration items

chown -R mysql .

chgrp -R mysql .

Initialize mysql:

scripts/mysql_install_db –user=mysql

Change permissions of mysql data directory

5. Start mysql

5.1 Start mysql-5.5.32

cd /mysqlsoft/mysql1

bin/mysqld_safe –user=mysql &

5.2 Start mysql-5.6.31

cd /mysqlsoft/mysql2

bin/mysqld_safe –user=mysql &

5.3 Check the startup status of mysql

[root@mysql mysql2]# ps -ef | grep mysql

root   6329 2853 0 13:19 pts/0  00:00:00 /bin/sh bin/mysqld_safe –user=mysql

mysql   6607 6329 0 13:19 pts/0  00:00:00 /mysqlsoft/mysql1/bin/mysqld –basedir=/mysqlsoft/mysql1/ –datadir=/data/mysql1/ –plugin-dir=/mysqlsoft/mysql1//lib/plugin –user=mysql –log-error=/data/mysql1//mysql.localdomain.err –pid-file=/data/mysql1//mysql.localdomain.pid –socket=/mysqlsoft/mysql1/mysql.sock –port=3301

root   6630 2853 0 13:20 pts/0  00:00:00 /bin/sh bin/mysqld_safe –user=mysql

mysql   6774 6630 0 13:20 pts/0  00:00:00 /mysqlsoft/mysql2/bin/mysqld –basedir=/mysqlsoft/mysql2 –datadir=/data/mysql2 –plugin-dir=/mysqlsoft/mysql2/lib/plugin –user=mysql –log-error=/data/mysql2/mysql.localdomain.err –pid-file=/data/mysql2/mysql.localdomain.pid –socket=/mysqlsoft/mysql2/mysql.sock –port=3302

5.4 Delete other items in mysql

1. Change the root user and change the password

2. Delete anonymous users

3. Delete some lines in mysql.db, which define that any user can access the test database, or databases starting with test_.

DELETE FROM mysql.db WHERE Db LIKE ‘test%';

Summary

The above is the entire content of this article. I hope it can be of some help to everyone’s study and work.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn