Detailed explanation of compiling and installing MySQL 5.6 on CentOS and installing multiple MySQL instances

Detailed explanation of compiling and installing MySQL 5.6 on CentOS and installing multiple MySQL instances

--1. Create a new group and user for mysql

# useradd -M -s /sbin/nologin mysql

--2. Install required libraries and compilers

# yum install ncurses-devel openssl-devel cmake -y

--3. Unzip

# tar zxvf mysql-5.6.35.tar.gz
# cd mysql-5.6.35

--4. Compile and install

# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
# make
# make install

--5. Copy the template as a configuration file

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

--6. Set mysql permissions

# chown -R mysql.mysql /usr/local/mysql/

--7. Initialize mysql database

# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
# chown -R root /usr/local/mysql/
# chown -R mysql /usr/local/mysql/data/


--8. Set MySQL to start automatically at boot

# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig mysqld on

--9. Test and run mysql

#service mysqld start

--10. Change the mysql administrator password

#/usr/local/mysql/bin/mysqladmin -u root password 'Password to be set'

--11. Log in to mysql using user

# /usr/local/mysql/bin/mysql -u root -p

--12. Add environment variables

# echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile
# source /etc/profile

CentOS 6.5 minimal compilation and installation of mysql 5.5.35 configuration multiple instances

1. Turn off the firewall

1234567 [root@mysql ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@mysql ~]# chkconfig iptables off
[root@mysql ~]# chkconfig iptables --list
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off

2. Turn off selinux

12 [root@mysql ~]# setenforce 0
[root@mysql ~]# vim /etc/sysconfig/selinux

Modify the following line;

SELINUX=disabled
12 [root@mysql ~]# getenforce 
Permissive

3. Install mysql dependency packages and compilation tools;

1234 [root@mysql ~]# yum install libaio-devel -y
[root@mysql ~]# yum install -y ncurses-devel
[root@mysql ~]# yum install -y gcc gcc-c++ 
[root@mysql ~]# yum install -y cmake

4. Preparation before installation;

4.1. Installation path:

1 [root@mysql ~]# mkdir /usr/local/mysql

4.2. Database path:

1 [root@mysql ~]# mkdir /data/mysql -p

4.3. Create users and user groups

12 [root@mysql ~]# groupadd mysql
[root@mysql ~]# useradd -r -g mysql -s /bin/false mysql

4.4. Grant permissions to the data storage directory

1 [root@mysql ~]# chown mysql:mysql -R /data/mysql

5. Compile and install mysql 5.5.35

1234567 [root@mysql ~]# yum install -y lrzsz
root@mysql ~]# mkdir /package
[root@mysql ~]# cd /package/
[root@mysql package]# tar xf mysql-5.5.32.tar.gz 
[root@mysql package]# cd mysql-5.5.32
[root@mysql mysql-5.5.32]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
[root@mysql mysql-5.5.32]# make && make install

6. Create a multi-instance database file storage location;

12345678 [root@mysql ~]# mkdir -p /data/{3306,3307}/data
[root@mysql ~]# tree /data
/data
|-- 3306
| `-- data
`-- 3307
  `--data
4 directories, 0 files

7. Modify the configuration file (my.cnf) as follows and put it in the 3306 and 3307 directories respectively;

123456789 [root@mysql 3306]# vim my.cnf 
[client]
port = 3306
socket = /data/3306/mysql.sock
[mysqld]
port = 3306
socket = /data/3306/mysql.sock
datadir = /data/3306
server-id = 3306

8. Initialize the database;

Note: You need to specify a different data directory when initializing the database

123 [root@mysql mysql-5.5.32]# cd /usr/local/mysql/
[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306
[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307

9. Start multiple instances, and the startup script can be added to the startup file.

12 [root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 >/dev/null &  
[root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 >/dev/null &

9.1. Check the port;

12345678 [root@mysql mysql]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name  
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 11621/mysqld    
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1266/sshd      
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11338/mysqld    
tcp 0 0 :::22 :::* LISTEN 1266/sshd      
udp 0 0 0.0.0.0:68 0.0.0.0:* 969/dhclient

10. Log in to a multi-instance database

12 [root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3306 -S /data/3306/mysql.sock
[root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3307 -S /data/3307/mysql.sock

11. Close MySQL multi-instance mode

12 [root@mysql mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3306 -S /data/3306/mysql.sock shutdown  
[root@mysql mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3307 -S /data/3307/mysql.sock shutdown
cat ​/etc/my.cnf 
[mysqld1]
datadir=/data/mysql
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
skip-name-resolve
server-id=1221
max_connections = 2000
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
innodb_buffer_pool_size = 2G
innodb_additional_mem_pool=16M
innodb_log_file_size=256M
innodb_flush_log_at_trx_commit=2
character_set_server=utf8
collation_server = utf8_general_ci
replicate_ignore_db = mysql
slave-skip-errors=all
relay_log=/data/mysql/
[mysqld2]
port=3307
server-id=1222
log-error=/tmp/mysqld2.log
datadir=/data/mysql_live
socket=/tmp/mysql2.sock
user=mysql
symbolic-links=0
skip-name-resolve
character_set_server=utf8
collation_server = utf8_general_ci
max-connections=500
default-storage-engine=INNODB
innodb_file_per_table
log-bin=mysql-bin
relay-log-info-repository=TABLE
master-info-repository=TABLE
expire_logs_days=10
binlog_format=ROW
transaction-isolation=READ-COMMITTED
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
slow_query_log=TRUE
slow_query_log_file=/tmp/mysqld_slow_query2.log
long_query_time=3
replicate_ignore_db = mysql
slave-skip-errors=all
[mysqld3]
server-id=1223
port=3308
log-error=/tmp/mysqld3.log
datadir=/data/mysql
socket=/tmp/mysql3.sock
user=mysql
symbolic-links=0
skip-name-resolve
character_set_server=utf8
collation_server = utf8_general_ci
max-connections=500
default-storage-engine=INNODB
innodb_file_per_table
log-bin=mysql-bin
relay-log-info-repository=TABLE
master-info-repository=TABLE
expire_logs_days=10
binlog_format=ROW
transaction-isolation=READ-COMMITTED
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
slow_query_log=TRUE
slow_query_log_file=/tmp/mysqld_slow_query3.log
long_query_time=3
replicate_ignore_db = mysql
slave-skip-errors=all
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/data/mysql/mysqld.pid


<<:  Detailed explanation of Docker basic network configuration

>>:  Native js to achieve seamless carousel effect

Recommend

Example verification MySQL | update field with the same value will record binlog

1. Introduction A few days ago, a development col...

Bugs encountered when using mybatis-generator with mysql8.0.3 in IDEA

1. Add the plug-in and add the following configur...

Mac VMware Fusion CentOS7 configuration static IP tutorial diagram

Table of contents Install CentOS7 Configuring Sta...

Detailed explanation of custom swiper component in JavaScript

Table of contents Effect display Component Settin...

The webpage cannot be opened because the div element lacks a closing tag

At first I thought it was a speed issue, so I late...

Solution to the problem that order by is not effective in MySQL subquery

By chance, I discovered that a SQL statement prod...

Sample code for installing ASPNET.Core3.0 runtime in Linux

# The following examples are for x64-bit runtime ...

Implementation of formatting partitions and mounting in Centos7

Linux often encounters situations such as adding ...

How to connect JDBC to MySQL 5.7

1. First prepare the MySQL and Eclipse environmen...

mysql5.7.17.msi installation graphic tutorial

mysql-5.7.17.msi installation, follow the screens...

js implements axios limit request queue

Table of contents The background is: What will ha...

Today I encountered a very strange li a click problem and solved it myself

...It's like this, today I was going to make a...

JavaScript to achieve text expansion and collapse effect

The implementation of expanding and collapsing li...