Install MySQL5.7 from CentOS source code

This document will install mysql5.7.20 in the /usr/local/ahsl/mysql3307 directory, and the port number is 3307.


1. Operating system preparation The
operating system version is CentOS6.5 or later. If the memory exceeds 4GB, install a 64-bit system, otherwise install a 32-bit system. The key bottleneck of MySQL performance is disk performance. Be sure to use high-speed disks, such as RAID composed of SSD or SAS.

1) Confirm to close SELINUX
[root@localhost ~]# cat /etc/selinux/config
SELINUX=disabled

2) Optimize Linux kernel parameters
vi /etc/security/limits.conf


* soft nofile 655350
* hard nofile 655350
* soft nproc 655350
* hard nproc 655350
wq After saving the file, disconnect or restart the system, use ulimit -a to check and confirm





2. Create the ahsl directory
mkdir /usr/local/ahsl
cd /usr/local/ahsl

3. Install the compilation dependency package gcc/c++/ ncurses /perl
yum install -y gcc gcc-c++ ncurses-devel perl
4. Install the compilation tool cmake

wget --no-check-certificate https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz

tar -xzvf /usr/local/ahsl/cmake-3.4.1.tar.gz  

cd /usr/local/ahsl/cmake-3.4.1 

./bootstrap

make && make install 5. Add mysql user groupadd mysql useradd



in centos r -g mysql mysql 6. Download MySQL source code wget --no-check-certificate https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz 7. Unzip the tar - zxvf mysql-5.7.20.tar.gz 8. Create mysql data directory mkdir -p /usr/local/ahsl/mysql3307/data chown mysql:mysql /usr/local/ahsl/mysql3307/data 9. Compile





















cd /usr/local/ahsl/mysql-5.7.20

wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

tar xzf boost_1_59_0.tar.gz

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/ahsl/mysql3307 \
-DMYSQL_UNIX_ADDR=/usr/local/ahsl/mysql3307/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/ahsl/mysql3307/data \
-DMYSQL_TCP_PORT=3307 \
-DWITH_BOOST=boost_1_59_0


make && make install

10. 设置mysql安装目录权限
chown -R mysql:mysql /usr/local/ahsl/mysql3307

11. Configure the number of mysql connections and optimize configuration parameters

For mysql5.7, the maximum number of connections must usually be configured, and other parameters can be defaulted.
vi /usr/local/ahsl/mysql3307/my.cnf

[mysqld]
max_connections = 4096

For high-performance database servers, it can be optimized according to the hardware performance of the server. Related articles on specific parameters:
https://dev.mysql.com/doc/ refman/5.7/en/server-system-variables.htmlIn



fact, mysql5.7 can already be dynamically tuned by SET GLOBAL var=value, but it will fail after restarting.
In mysql8.0, you can use SET PERSIST var=val to dynamically modify and save parameters.


12. Initialize the database
/usr/local/ahsl/mysql3307/bin/mysqld --initialize --user=mysql

to record the randomly generated default password quw&sioK)48f.

13. Start the mysql service
/usr/local/ahsl/mysql3307/bin/mysqld_safe &
prompt: stop the mysql service /usr/local/ahsl/mysql3307/support-files/mysql.server stop


14. Log in to mysql and change the root password default password , create ahsl user
/usr/local/ahsl/mysql3307/bin/mysql -uroot -p 'Random password generated during initialization'

set password=password('y4yhl9t');

grant all privileges on *.* to 'ahsl'@'%' identified by 'y4yhl9t';

flush privileges;

15. As the system automatically starts
vi /etc/rc.d/rc.local

, add mysql startup in front of JDK or in front of tomcat.
/usr/local/ahsl/mysql3307/bin/mysqld_safe &
After restarting, use netstat –anpt to check whether port 3307 is listening, use sqlyog to connect




16. Others
If there are multiple mysql instances under the same operating system, be sure to remove /etc/ my.cnf Because this is a global configuration file for mysql parameters, the recommended way is to place this file in the installation directory of each instance.


17. References
https://www.insp.top/article/make-install-mysql-5-7

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326034775&siteId=291194637