CentOS 7.4 use the source code package to compile and install MySQL 5.7.20
Useyum
The installed MySQL version is old but stable. If you want to try the latest features or specify special features, you need to compile and install them manually.
1. Download the installation package(1) download the MySQL source code at https://dev.mysql.com/downloads/mysql /:
- In
Select Operationg System
SelectSource Code
;
- In the following
Select OS Version
SelectGeneric Linux(Architecture Independent)
;
- Then you can see the following section
Compressed TAR Archive
, ClickDownload
;
- On the displayed page, select
No thanks, just start my download
You can start the download.
After the download is complete, useWinSCP
Copy files to/usr/local/src
Directory.
You can also use the following method to download the source code package in Linux./usr/local/src
Directorywget
Download:
cd /usr/local/srcwget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz
(2) download boostDownload URL: http://www.boost.org/users/download/ this version of MySQL requires boost version is 1.59, the link is: http://www.boost.org/users/history/version_1_59_0.html below give boost 1.59.0 link, in/usr/local/src
Directorywget
Download
wget --no-check-certificate http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
Ii. Compilation and Installation(1) install necessary software dependencies:yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
(2) decompress the MySQL source file:tar -zxvf mysql-5.7.20.tar.gz
Move the boost package to the decompressed source file directory:
mv boost_1_65_1.tar.gz mysql-5.7.20
(3) Go to the MySQL source file directory, create configure as the compilation directory, and enter the directory:cd mysql-5.7.20mkdir configurecd configure
(4) use cmake to generate the compiling environment:cmake .. -DBUILD_CONFIG=mysql_release \-DINSTALL_LAYOUT=STANDALONE \-DCMAKE_BUILD_TYPE=RelWithDebInfo \-DENABLE_DTRACE=OFF \-DWITH_EMBEDDED_SERVER=OFF \-DWITH_INNODB_MEMCACHED=ON \-DWITH_SSL=bundled \-DWITH_ZLIB=system \-DWITH_PAM=ON \-DCMAKE_INSTALL_PREFIX=/var/mysql/ \-DINSTALL_PLUGINDIR="/var/mysql/lib/plugin" \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EDITLINE=bundled \-DFEATURE_SET=community \-DCOMPILATION_COMMENT="MySQL Server (GPL)" \-DWITH_DEBUG=OFF \-DWITH_BOOST=..
If an error occurs during compilation, delete cmakecache.txt and re-compile it:
rm -rf CMakeCache.txt
If the following prompt appears, the compilation environment is successfully generated:
-- Configuring done-- Generating done
(5) Compile with make:make
After compilation, the following information appears:
[100%] Building CXX object sql/CMakeFiles/udf_example.dir/udf_example.cc.oLinking CXX shared module udf_example.so[100%] Built target udf_example[100%] Built target my_safe_process
(6) install MySQL:make install
3. initialize the database(1) Add a mysql user:useradd -s /sbin/nologin mysql
(2) create a database folder and log folder, and change the user to mysql:mkdir /mysql_datamkdir /var/mysql/logchown -R mysql:mysql /mysql_data/chown -R mysql:mysql /var/mysql/log
(3) modify the configuration filevim /etc/my.cnf
Replace the content under [mysqld]:
[mysqld]port=3306datadir=/mysql_datalog_error=/var/mysql/log/error.logbasedir=/var/mysql/
(4) initialize the database:/var/mysql/bin/mysqld --initialize --user=mysql
Check whether the data file is generated:
[Root @ localhost configure] # ll/mysql_data/total usage 110620-rw-r -----. 1 mysql 56 October 2 19:44 auto. cnf-rw-r -----. 1 mysql 419 October 2 19:44 ib_buffer_pool-rw-r -----. 1 mysql 12582912 October 2 19:44 ibdata1-rw-r -----. 1 mysql 50331648 October 2 19:44 ib_logfile0-rw-r -----. 1 mysql 50331648 October 2 19:44 ib_logfile1drwxr-x ---. 2 mysql 4096 October 2 19:44 mysqldrwxr-x ---. 2 mysql 4096 October 2 19:44 performance_schemadrwxr-x ---. 2 mysql 12288 October 2 19:44 sys
Check whether the log file is generated:
[Root @ localhost mysql] # ll/var/mysql/log/total usage 4-rw-r -----. 1 mysql 802 October 2 19:47 error. log
Iv. configuration of startup files and Environment Changes(1) configure the Startup File1. Copy the Startup file from the template file:
cp /var/mysql/support-files/mysql.server /etc/init.d/mysqld
2. Modify the Startup file:
vim /etc/init.d/mysqld
Find the following two rows:
basedir=datadir=
To:
basedir=/var/mysql/datadir=/mysql_data
3. Start mysql:
[root@localhost mysql]# /etc/init.d/mysqld startStarting MySQL. SUCCESS!
You can see the prompt that the instance has been started successfully. Of course, you can also use systemctl to start MySQL, but there is no prompt after execution.
[root@localhost ~]# systemctl start mysqld
(2) Set MySQL to automatically start upon startup:[root@localhost ~]# systemctl enable mysqldmysqld.service is not a native service, redirecting to /sbin/chkconfig.Executing /sbin/chkconfig mysqld on
(3) Configure MySQL environment variables:vim /root/.bash_profile
Find the following line:
PATH=$PATH:$HOME/bin
To:
PATH=$PATH:$HOME/bin:/var/mysql/bin
(4) modifyroot
Initial Password1. Viewroot
MySQL does not support installation and use an empty password to log on from 5.7. Therefore, you must first query the temporary password generated by the Program:
[root@localhost ~]# cat /var/mysql/log/error.log |grep 'A temporary password'2017-11-13T06:28:23.096812Z 1 [Note] A temporary password is generated for root@localhost: wa&sk371_,US
Part of bkv, dy,) after the last colon is the initial password.2. log on to MySQL and change the initial password: Use the initial password to log on to MySQL:
[root@localhost ~]# mysql -uroot -pEnter password:
Change the root password immediately after Logon:
mysql> alter user 'root'@'localhost' identified by 'your_password';Query OK, 0 rows affected (0.00 sec)
Whereyour_password
It is your new password. The new password must be a strong one. The password must contain uppercase and lowercase letters, numbers, and punctuation marks. The length should be more than 6 characters.
(5) testAfter setting, restart the server and check whether MySQL is automatically started:
[root@localhost ~]# ps aux |grep mysqldroot 816 0.0 0.1 115388 1716 ? S 14:45 0:00 /bin/sh /var/mysql//bin/mysqld_safe --datadir=/mysql_data --pid-file=/mysql_data/localhost.localdomain.pidmysql 1034 1.0 17.6 1122908 179688 ? Sl 14:45 0:00 /var/mysql/bin/mysqld --basedir=/var/mysql/ --datadir=/mysql_data --plugin-dir=/var/mysql//lib/plugin --user=mysql --log-error=/var/mysql/log/error.log --pid-file=/mysql_data/localhost.localdomain.pid --port=3306root 1119 0.0 0.0 112676 984 pts/1 R+ 14:46 0:00 grep --color=auto mysqld
If the above information is displayed, it means that you have completed the manual compilation and installation of MySQL5.7.20 on CentOS7.4.