Recently this time, in looking at MySQL, installed, also applied, for the production environment, generally choose to use the source code installation, when installed, you can customize the relevant path and content, for the production environment more effective. Compared to the installation of MySQL 5.5, MySQL 5.7 installation is similar, the only difference is 5.7 in the installation, need a component, boost, and must be 1.59, the version is not good, so download should pay attention to.
In the MySQL official website when downloading, provides two kinds of source code, one is with the boost, the direct compilation installs, one is does not have the boost, needs to download the boost to install by oneself. We chose to use the version without Boost, after the boost was downloaded, the boost was copied to the/usr/local/boost directory, and then the MySQL source was unzipped and compiled. The compiled code is:
CMake. -dcmake_install_prefix=/app/mysql_5. 7.22 -dmysql_datadir=/app/mysql_5. 7.22/DATA-DDEFAULT_CHARSET=UTF8-DDEFAULT_COLLATION=UTF8_GENERAL_CI-DMYSQL_USER=MYSQL-DWITH_MYISAM_ storage_engine=1 -dwith_innobase_storage_engine=1 -dwith_archive_storage_engine=1 - dwith_blackhole_storage_engine=1 -dwith_memory_storage_engine=1 -ddownload_boost=1 - Dwith_boost=/usr/local/boost
The entire compilation process is very long, by default, the compile time has specified Basedir and datadir, these two paths are the default, in the process of subsequent database initialization, can be redefined in different situations. Once the compilation is complete, you can make && made install.
If it is a source with BOOST, also specify dwith_boost=. /boost, this is a relative path.
After the installation is complete, the database needs to be initialized, this time, you can set the initialization of the DataDir, the later database is applied in this directory. In the initialization process, compared to 5.5 a little difference, after 5.5 initialization is complete, the default login database does not require a password. And in 5.7,--initialize-insecure and--initialize there are two option, the two properties have a difference, that is, in initialize time, will be [email protected] Generate a random password, This password will be written to the database log, the password can be obtained through grep log, and then use the password when logging in, after logging in, through update to modify, and--initialize-insecure at the time of initialization, Like 5.5, you will not generate a password with the root user, and you can log in directly with a blank password.
./mysqld--initialize-insecure--user=mysql--basedir=/app/mysql--datadir=/data/mysql57/3307/data/--pid- file=/data/mysql57/3307/tmp/3307_pid--socket=/data/mysql57/3307/tmp/3307_socket
When initializing, specify the PID, socket and other file location, by default directly in the data directory, generate a host name of the log file, at the time of initialization, directly on the screen output a paragraph, indicating no password.
2018--05t00: +:1 [Warning] [email protected] is created with an empty Password! Please consider switching off the--initialize-insecure option.
It is also important to note that the owner and array of the file are MySQL-enabled users, that is mysql.mysql, in the entire MySQL basedir and DataDir.
Because it is a custom source installation, MySQL startup script can not be used directly, thinking of writing a script to control the mysql5.7 start and stop. The following is the code content.
basedir=/app/Mysqlbindir= $BASEDIR/Binmysql_bin= $BINDIR/Mysqld_safemysqladmin=/usr/local/mysql/bin/Mysqladmindatadir=/data/mysql57/3307/datamycnf=/data/mysql57/3307/My.cnfport=3307SOCKET=`grepSocket $MYCNF |grep$PORT |awk '{print $}'' usage () {Echo "$ A usage: {start|stop|reload}"}mysqld_start () {if[ `PS-ef|grep "port= $PORT"|grep-Vgrep|WC-L '-ge1 ] Then Echo "The MYSQL SERVER is running" Else if[-X $MYSQL _bin] && [-F $MYCNF] Then$MYSQL _bin--defaults-file= $MYCNF &1>>/tmp/mysql.log2>&1 Echo$? >>/tmp/Mysql.logSleep 2 [ `PS-ef|grep "port= $PORT"|grep-Vgrep|WC-L '-ge1] && Action"The MYSQL SERVER starting"/bin/true|| Action"The MYSQL SERVER starting"/bin/false Else Echo "MISSING startup_config,please CHECK the CONFIG in $MYCNF" fi fi}mysqld_stop () {if[ `PS-ef|grep "port= $PORT"|grep-Vgrep|WC-L '-lt1 ] Then Echo "The MYSQL SERVER is not running" Else$MYSQLADMIN-S $SOCKET shutdownPS-ef|grep "port= $PORT"|grep-Vgrep|WC-l [$? -eq0] && Action"The MYSQL SERVER stopping"/bin/true|| Action"The MYSQL SERVER stopping"/bin/false fi}main () {if[$#-ne1 ] ThenusageElse Case " $" inch 'Start') Mysqld_start;; 'Stop') mysqld_stop;; 'Reload') Mysqld_stop Mysqld_start ;; *) UsageEsac fi}main $*
In this code, basically are very common start and stop function, judge whether to start, is based on the process to distinguish, based on the contents of the configuration file to judge, in addition, because MySQL at the start of time delay, can not start to immediately determine whether there is a process, so you need to start the script when the sleep , usually 2 seconds is enough. Test the usability of the script below.
[Email protected] bin]#SHMysql_server.SHStop2018- --09T01: -: One.096443Z Mysqld_safe mysqld from PIDfile/data/mysql57/3307/tmp/3307_pid ended0The MYSQL SERVER stopping [OK][[email protected] bin]#SHMysql_server.SHstopthe MYSQL SERVER is not running[[email protected] bin]#SHMysql_server.SHreloadthe MYSQL SERVER is not running2018- --09T01: -: A.379632Z Mysqld_safe Logging to'/data/mysql57/3307/data/server129.err'.2018- --09T01: -: A.411184Z Mysqld_safe starting mysqld daemon with databases from/data/mysql57/3307/datathe MYSQL SERVER starting [OK][[email protected] bin]#SHMysql_server.SHStop2018- --09T01: -: -.241711Z Mysqld_safe mysqld from PIDfile/data/mysql57/3307/tmp/3307_pid ended0The MYSQL SERVER stopping [OK][[email protected] bin]#SHMysql_server.SHStart2018- --09T01: -: -.846842Z Mysqld_safe Logging to'/data/mysql57/3307/data/server129.err'.2018- --09T01: -: -.878461Z Mysqld_safe starting mysqld daemon with databases from/data/mysql57/3307/datathe MYSQL SERVER starting [OK][[email protected] bin]#
The basic functions seem to be reasonable, but there are some things that are certain, such as how these scripts output when they start, and how not to show them.
MySQL 5.7 startup script