Home  >  Article  >  Database  >  Detailed introduction to centos compilation and installation of mysql5.6 and sample code sharing for installing multiple mysql

Detailed introduction to centos compilation and installation of mysql5.6 and sample code sharing for installing multiple mysql

黄舟
黄舟Original
2017-03-25 13:51:461043browse

This article mainly introduces centos compilation and installation of mysql 5.6 and the detailed explanation of installing multiple mysql instances. Friends in need can refer to the following

--1. Create new groups and users for mysql

# useradd -M -s /sbin/nologin mysql

--2. Install the required libraries and compiler

# 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.Initializemysql 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 Self-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 '要设置的密码'

--11. Log in using user mysql

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

--12. Add environment variable

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

Centos 6.5 minimum compilation and installation MYSQL 5.5.35 Configure multiple examples

# 1 1. Close the firewall r

2. Close selinux

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

Modify the following line;

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

3. Install mysql dependency packages and compilation tools;

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

4. Preparation before installation;

4.1.Installation path:

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.2.Database path:

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

4.3.Creation Users and user groups

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

4.4. Grant permissions to the data storage directory

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

5. Compile and install mysql 5.5.35

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

6. Create multiple The storage location of the instance database file;

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

7. Modify the configuration file (my.cnf) with the following lines and place it in the 3306 and 3307 directories respectively;

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

8. Initialize the database;

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

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

9. To start multiple instances, the startup script can be added to the boot auto-start file.

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.1. View port;

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 &

10. Log in to multi-instance database

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

11. Close mysql multi-instance mode

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

The above is the detailed content of Detailed introduction to centos compilation and installation of mysql5.6 and sample code sharing for installing multiple mysql. For more information, please follow other related articles on the PHP Chinese website!

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