centos compilation and installation of mysql 5.6 and installation of multiple mysql instances
- 2021-07-06 12:00:01
- OfStack
--1. Create new groups and users for mysql
# useradd -M -s /sbin/nologin mysql
--2. Install required libraries and compilers
# yum install ncurses-devel openssl-devel cmake -y
--3. Decompression
# 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 the 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 boot and start
# 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. Modify the mysql administrator password
#/usr/local/mysql/bin/mysqladmin -u root password ' Password to set '
--11. Use user login mysql
# yum install ncurses-devel openssl-devel cmake -y
0
--12. Add environment variables
# echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile
# source /etc/profile
CentOS 6.5 Minimize 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
# yum install ncurses-devel openssl-devel cmake -y
3
Modify the following 1 line;
# yum install ncurses-devel openssl-devel cmake -y
4
3. Install mysql dependency package and compilation tool;
# yum install ncurses-devel openssl-devel cmake -y
5
4. Prepare before installation;
4.1. Installation path:
# yum install ncurses-devel openssl-devel cmake -y
6
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. Give data storage directory permission
# yum install ncurses-devel openssl-devel cmake -y
9
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 the storage location of multi-instance database files;
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 following lines of the configuration file (my. cnf) and put them into 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, initializing the database;
Note: Different data directories need to be specified 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 self-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. View 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 the 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. Turn off 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