1. Compile and install mysql from source code (version 5.7)
download link:
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz
# (After MySQL version 5.7, boost is necessary. It is recommended to uninstall the boost library that comes with the system, and compile the source code to install a higher version.
Boost library is a general term for some C++ program libraries that provide extensions to the C++ language standard library )
(1) Environmental preparation:
[root@Wg64 ~]# ls
mysql-boost-5.7.18.tar.gz nginx-1.10.3.tar.gz nginx.conf pcre-8.38.tar.gz php-7.0.18.tar.gz
#Uninstall the system's own boots library
[root@Wg64 ~]# yum -y remove boost-*
#Uninstall the mysql that comes with the system
[root@Wg64 ~]# yum -y remove mysql
[root@Wg64 ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-5.el6_6.x86_64
[root@Wg64 ~]# rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64
[root@Wg64 ~]# rpm -qa | grep mysql
#Install the necessary resource packs
It is recommended to use the network yum source. The version of the software package that comes with the RHEL6.5 CD is not enough. The compilation of mysql-boost-5.7.18.tar.gz requires a relatively high version of the software package, and the version of cmake should not be lower than 2.8.
#install dependencies
[root@Wg64 ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel
(2) Add users and groups
[root@Wg64 ~]# groupadd mysql
[root@Wg64 ~]# useradd -M -s /sbin/nologin -r -g mysql mysql
(3) Create an installation directory and a data storage directory
[root@Wg64 ~]# mkdir -p /server/mysql
(4) Upload the source package and decompress the source package
[root@HK64 LAMP]# ls
[root@Wg64 ~]# tar zxf mysql-boost-5.7.18.tar.gz -C /server/
(5) Move boost to /server/
[root@HK64 server]# cd mysql-5.7.18/ (file containing boost library)
#Move the boots file to /server/mysql/
[root@Wg64 mysql-5.7.18]# mv boost/ /server/mysql
[root@Wg64 mysql-5.7.18]# cd /server/mysql
[root@Wg64 mysql]# ls
boost
(6) Configuration parameters
[root@Wg64 mysql]# cd ../
[root@Wg64 server]# ls
mysql mysql-5.7.18
[root@Wg64 server]# cd mysql-5.7.18/
[root@Wg64 mysql-5.7.18]#cmake -DCMAKE_INSTALL_PREFIX=/server/mysql -DMYSQL_DATADIR=/server/mysql/data -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/server/mysql/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=l -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/server/mysql/boost
These compile parameters help find methods:
http://www.mysql.com →→ Documentation →→ Select the corresponding version (5.7) Installation & Upgrades →→ Installing MySQL from Source →→ MySQL Source-Configuration Options
Final URL h ttps://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
DCMAKE_INSTALL_PREFIX : Specifies the installation directory of the MySQL program, default /usr/local/mysql
DEFAULT_CHARSET: Specifies the server default character set, default latin1
DEFAULT_COLLATION: Specifies the server default collation, default latin1_general_ci
ENABLED_LOCAL_INFILE: Specifies whether to allow local execution of LOAD DATA INFILE, default OFF
WITH_COMMENT: Specify compilation remarks
WITH_xxx_STORAGE_ENGINE: Specify the storage engine that is statically compiled to mysql, MyISAM, MERGE, MEMBER and CSV four engines are compiled to the server by default, and do not need to be specified.
WITHOUT_xxx_STORAGE_ENGINE: Specify the storage engine not to compile
SYSCONFDIR: Initialization parameter file directory
MYSQL_DATADIR: Data file directory
MYSQL_TCP_PORT: Service port number, default 3306
MYSQL_UNIX_ADDR: socket file path, default /tmp/mysql.sock
compile
mysql-5.7.18.tar.gz will take up a lot of system resources when compiling. It is recommended to use multiple cores to compile at the same time, otherwise the compilation may fail
(7) Compile
#View server cpu count
[root@Wg64 mysql-5.7.18]# grep processor /proc/cpuinfo | wc -l
2
[root@Wg64 mysql-5.7.18]# make -j 2
(8) Installation
[root@xuegod63 mysql-5.7.18]# make install
(9) Modify directory permissions
[root@Wg64 mysql-5.7.18]# chown -R mysql:mysql /server/mysql/
(10) Generate configuration file
#Move backup or delete the original server configuration file
[root@Wg64 mysql-5.7.18]# mv /etc/my.cnf{,.bak}
#Because there is no such configuration template file in version 5.7/server/mysql/support-files/my-default.cnf
#Write my.cnf file by yourself
[root@Wg64 mysql-5.7.18]#vim /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#default
user = mysql
basedir = /server/mysql
datadir = /server/mysql/data
port = 3306
pid-file = /server/mysql/data/mysql.pid
socket = /server/mysql/mysql.sock
character-set-server=utf8
[client]
socket = /server/mysql/mysql.sock
(11) Generate a service startup script
grep chkconfig ./* -R -color
[root@Wg64 mysql]# cp /server/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@Wg64 mysql]# chmod +x /etc/init.d/mysqld
[root@Wg64 mysql]# chkconfig --add mysqld
[root@Wg64 mysql]# chkconfig mysqld on
[root@Wg64 mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
(12) Initialize the database
[root@Wg64 mysql]# /server/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/server/mysql --datadir=/server/mysql/data
(13) Start the service
[root@Wg64 mysql]# service mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/server/mysql/data/Wg64.err'.
SUCCESS!
[root@Wg64 mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
(15) Optimize the calling command path
#Add path path: vim /etc/profile Add the following 2 lines at the end of the file
export MYSQL_HOME=/server/mysql
export PATH=$PATH:$MYSQL_HOME/bin
# make changes take effect
source /etc/profile
or
[root@Wg64 mysql]# ln -s /server/mysql/bin/* /usr/local/bin/
(14) Modify the mysql password to test login:
[root@Wg64 ~]# mysqladmin -u root password "123456"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
Test login successful:
Please refer to the link for source code compilation LNMP: http://blog.51cto.com/13719714/2110940
Please refer to the link for source code compilation LAMP: http://blog.51cto.com/13719714/2109227
For Apache basic tuning, please refer to the link: http://blog.51cto.com/13719714/2109007