Multiple configuration instances of mysql data are installed in Centos

  • 2020-06-15 10:23:41
  • OfStack

Note: This document does two instances of MYSQL, multiple instance methods, and so on

LINUX Operating System :centOS6.3 64bit(with default development kit installed)
Database 1:
MYSQL version: mysql - 5.0.56
PORT:3306
The system directory: / usr/local/mysql3306
Database 2:
MYSQL version: mysql - 5.1.72
PORT:3307
The system directory: / usr/local/mysql3307

1. Installation of development kit (using default CENTOS update source):

# yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*

2. Close iptables and SELINUX
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled

---------------
3. Install the mysql database instance
1. Download the compilation package:
# su -
# mkdir ~/src
# cd src
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz

2. Initial configuration before installation:
1). Create 1 Mysql user
# useradd mysql  

2). Create data and log subdirectories under mysql
# mkdir /usr/local/mysql{3306,3307}/data          
# mkdir /usr/local/mysql{3306,3307}/log

3). Modify the permissions of the owner and group of the directory
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/data/
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/log/
# chmod 750 /usr/local/mysql{3306,3307}/data      
# chmod 750 /usr/local/mysql{3306,3307}/log  

4). Create mysql related directories and configure permissions
# mkdir -p /usr/local/mysql{3306,3307}/etc
# chown -R mysql.mysql /usr/local/mysql{3306,3307}/etc
# mkdir -p /var/run/mysqld{3306,3307}
# chown -R mysql.mysql /var/run/mysqld{3306,3307}
# mkdir -p /var/lib/mysqld{3306,3307}
# chown -R mysql.mysql /var/lib/mysqld{3306,3307}
# cp /etc/my.cnf /usr/local/mysql{3306,3307}/etc

3. Unpack, compile and install
Compile database 1:
# cd ~/src
# tar -zxvf mysql-5.0.56.tar.gz    
# cd mysql-5.0.56  
./configure --prefix=/usr/local/mysql3306 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3306/etc  --localstatedir=/usr/local/mysql3306/data --with-tcp-port=3306 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3306.sock
# make
# make install

Compile database 2:
# cd ~/src
# tar -zxvf mysql-5.1.71.tar.gz    
# cd mysql-5.1.71
./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc  --localstatedir=/usr/local/mysql3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock
# make
# make install


4. Write mysql configuration item:
Database 1 configuration:

# vi /usr/local/mysql3306/etc/my.cnf
-------------------------------------------------------
[mysqld]
datadir=/usr/local/mysql3306/data
socket=/tmp/mysql3306.sock
user=mysql
port=3306
pid-file=/var/lib/mysqld3306/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3306/log/error.log
log=/usr/local/mysql3306/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3306/log/slowquery.log
log-bin= /usr/local/mysql3306/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3306.log
pid-file=/var/run/mysqld3306/mysqld.pid

-------------------------------------------------------
Database 2 configuration:
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
0

5. Add the library file path of mysql to the library file search path of the system
Method 1: Make soft links directly

# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
1
Method 2: Use ldconfig to import the system library
# echo "/usr/local/mysql3306/lib" >> /etc/ld.so.conf.d/mysql.conf
# ldconfig

6. Output the mysql header file to the system header file
# ln -s /usr/local/mysql3306/include/mysql /usr/include/mysql

Note: Only one mysql instance library file needs to be added to the system library, no multiple times

7. Go to the installation path of the corresponding instance and initialize the respective configuration scripts
Database 1 configuration:

# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
4
Database 2 configuration:
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
5
8. Copy the mysql startup script to the system services directory and change the script configuration
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
6
Database 1 configuration:
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
7
Search for the following lines, marked in red as added parameters:
---------------------------------------------
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
8
Database 2 configuration:
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
9
Search for the following lines, marked in red as added parameters:
---------------------------------------------
# su -
# mkdir ~/src
# cd src
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz
0


9. System startup item related configuration
Database 1 configuration:

# chkconfig --add mysqld3306  # Add boot service 
# chkconfig --level 35 mysqld3306 on  # Set up the mysql Start the 

Database 2 configuration:
# chkconfig --add mysqld3307  
# chkconfig --level 35 mysqld3307 on

10. Start mysql
Database 1 startup:
# service mysqld3306 start  

Database 2 startup:
# service mysqld3307 start  

Add mysql command set to system global variable
Note: If the mysql client has not been installed before, you can import the compiled mysql command set into the system global variable
You can then use the mysql command set directly without using absolute path access.
# echo "PATH=$PATH:/usr/local/mysql3306/bin;export PATH" >> /etc/profile
# source /etc/profile

12. Set up the initial account and log in the background:
Database 1:
# /usr/local/mysql3306/bin/mysqladmin -u root password 123456   # Set the super administrator password 
# /usr/local/mysql3306/bin/mysql -P3306 -S/tmp/mysql3306.sock -uroot -p123456 # Connect to database 

Database 2:
# / usr local/mysql3307 / bin/mysqladmin - u root password set # 123456 super administrator password
# / usr local/mysql3307 bin/mysql - P3307 - S/tmp/mysql3307 sock uroot - p123456 # connect to the database

Note: Since the mysql environment variable is added, the system background can log in directly using the mysql command. The absolute path is used here to standardize the operation
# mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456

13. Port test:

# su -
# mkdir ~/src
# cd src
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz
7

OK, done!


Related articles: