MySQL compilation installation
1. Create MySQL Account
[[email protected] ~]# useradd-s/sbin/nologin-m MySQL
2. Get the installation package
http://mirrors.sohu.com/mysql/
Choose the version you want (note the difference between the binary package name)
Format |
Package Name |
MySQL Source |
Mysql-5.7.18.tar.gz |
MySQL binary |
Mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz |
3. Compile and install
(1) Download the installation package
[Email protected] ~]# mkdir/opt/soft/
[Email protected] ~]# cd/opt/soft/
[Email protected] soft]# wget-q http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18.tar.gz
(2) Decompression, configuration
Unpacking the installation package
[Email protected] soft]# tar zxf mysql-5.7.18.tar.gz
Create a Directory
[Email protected] soft]# mkdir/opt/mysql57/
[Email protected] soft]# Mkdir/opt/mysql57/data
After MySQL version 5.5, use the CMake compilation tool
Installing components
[Email protected] soft]# yum-y install cmake make gcc gcc-c++ autoconf automake ncurses-devel libaio-devel bison-devel o Penssl-devel Zlib-devel Readline-devel
Compile the configuration:
Refer to Official Document Https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
-dcmake_install_prefix |
Specify the MySQL installation file directory |
-dmysql_datadir |
Specify the MySQL data file directory |
-dsysconfdir |
Specify the MySQL profile directory |
-dmysql_unix_addr |
Specify the Mysql.sock path |
-dmysql_tcp_port |
Specify MySQL Port |
-ddefault_charset |
Specifying the default character set |
-ddefault_collation |
Specify a default collation (Utf8_general_ci fast) |
-denabled_local_infile |
Import data from local |
-dwith_innobase_storage_engine |
Installing the InnoDB storage engine |
-dwith_archive_storage_engine |
Installing the archive Storage Engine |
-dwith_blackhole_storage_engine |
Installing the Blackhole Storage engine |
-dwithout_example_storage_engine |
Do not install the example storage engine |
-dwithout_federated_storage_engine |
Do not install the Federated storage Engine |
-dwithout_partition_storage_engine |
Do not install the partition storage engine |
-dwith_ssl |
Enable SSL Library Support |
-dwith_zlib |
Enable Zlib Library Support |
-dwith_readline |
Enable ReadLine Library Support |
-dwith_libwrap |
Close LibWrap Library Support |
-dextra_charsets |
Install all character Sets |
-ddownload_boost |
MySQL5.7.5 after the Boost library is required |
If you want to reconfigure the following command to execute:
Make clean
RM CMakeCache.txt
CMake. -DCMAKE_INSTALL_PREFIX=/OPT/MYSQL57 \
-dmysql_datadir=/opt/mysql57/data \
-DSYSCONFDIR=/ETC \
-dmysql_unix_addr=/tmp/mysql.sock \
-ddefault_charset=utf8 \
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \
-denabled_local_infile=1 \
-dwith_innobase_storage_engine=1 \
-dwith_archive_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-dwithout_example_storage_engine=1 \
-dwithout_federated_storage_engine \
-dwithout_partition_storage_engine \
-dwith_ssl=system \
-dwith_zlib=system \
-dwith_readline=1 \
-dwith_libwrap=0 \
-ddownload_boost=1 \
-dwith_boost=/usr/local/boost
(3) Compile and install
[Email protected] mysql-5.7.18]# make-j ' grep processor/proc/cpuinfo | Wc-l '
[[email protected] mysql-5.7.18]# make install
[Email protected] ~]# ls/opt/mysql57/
Bin COPYING docs include Lib man mysql-test README share support-files
Installation is successful!
(4) Setting up the configuration file
Precautions:
1, MySQL5.5 database by default to provide users with a number of profile templates, but MySQL5.5 after the Support-files directory has no configuration file template
2, in the CentOS6.6 version of the operating system to minimize the installation, there will be a my.cnf in the/etc directory, you need to rename this file to another name, such as:/etc/my.cnf.bak, otherwise, the file will interfere with the correct configuration of the source installed MySQL, resulting in the failure to start.
[Email protected] ~]# Mv/etc/my.cnf/etc/my.cnf.bak
#在启动MySQL服务时, will search my.cnf in a certain order, first in the/etc directory to find, will search "$basedir/my.cnf"
[Email protected] ~]# VI/ETC/MY.CNF
[Client]
port=3306
Socket=/tmp/mysql.sock
[Mysqld]
User=mysql
port=3306
Socket=/tmp/mysql.sock
Character-set-server=utf8
Collation-server=utf8_general_ci
basedir=/opt/mysql57/
datadir=/opt/mysql57/data/
tmpdir=/opt/mysql57/data/
Pid-file=/opt/mysql57/data/mysql.pid
Log_error=/opt/mysql57/data/mysql.err
Server-id = 137
Log_bin =/opt/mysql57/data/binlog
Slow_query_log = On
Long_query_time = 2
Slow_query_log_file =/opt/mysql57/data/query_log
Log_queries_not_using_indexes = On
The above is just a simple example
(5) Authorizing MySQL users
[Email protected] ~]# chown-r mysql.mysql/opt/mysql57/
(6) Initializing the database
[Email protected] ~]#/opt/mysql57/bin/mysqld--initialize--basedir=/opt/mysql57/--datadir=/opt/mysql57/data/-- User=mysql
[Email protected] data]# tail-f Mysql.err
2017-06-29t13:21:35.392220z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-06-29t13:21:36.231983z 0 [Warning] innodb:new log files created, lsn=45790
2017-06-29t13:21:36.364585z 0 [Warning] innodb:creating FOREIGN KEY constraint system tables.
2017-06-29t13:21:36.434567z 0 [Warning] No existing UUID have been found, so we assume that's the first time that thi s server has been started. Generating a new uuid:e09a3e70-5ccd-11e7-9dd2-c81f66c50de9.
2017-06-29t13:21:36.435687z 0 [Warning] Gtid table is not a ready-to-be used. Table ' mysql.gtid_executed ' cannot be opened.
2017-06-29t13:21:36.437654z 1 [Note] A temporary password is generated for [email protected]: Dh<pe9py7igk
The password file after initialization is also saved here in one copy.
[email protected] mysql57]# cat /root/.mysql_secret
# Password set for user ' [e-mail protected] ' at 2017-06-29 19:21:38
Dh<pe9py7igk
(7) Create a startup script
[email protected] mysql57]# CP support-files/mysql.server/etc/init.d/mysqld
[Email protected] mysql57]# chmod 755/etc/init.d/mysqld
[Email protected] mysql57]# Vi/etc/init.d/mysqld
basedir=/opt/mysql57/
datadir=/opt/mysql57/data/
mysqld_pid_file_path=/opt/mysql57/data/
[[email protected] data]#/etc/init.d/mysqld start
Starting MySQL. success!
MySQL service boot up
[Email protected] mysql]# chkconfig--add mysqld
[Email protected] mysql]# chkconfig mysqld on
Setting environment variables
[Email protected] data]# echo ' Export path= $PATH:/opt/mysql57/bin ' >>/etc/profile
[Email protected] data]# Source/etc/profile
[Email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/mysql57/bin:/root/bin
[Email protected] ~]# mysql-uroot-p
mysql> show databases;
ERROR 1820 (HY000): Must reset your password using ALTER USER statement before executing this statement.
Mysql> set Password=password (' 123456 ');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> alter user ' root ' @ ' localhost ' password expire never;
Query OK, 0 rows affected (0.01 sec)
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Another type of:
Grant all privileges on * * to [email protected] '% ' identified by ' 123456 ' with GRANT option;
Note the point:
Description of the installed dependent libraries
1> CMake
MySQL5.5 Use the CMake cross-platform tool to precompile the source code to set MySQL compilation parameters. such as: installation directory, data storage directory, character encoding, sorting rules, etc. You can install the latest version.
2> make
MySQL source code is written in C and C + + language, under Linux use make to compile and build code, requires that you must install make 3.75 or later
3> gcc4.4.6
GCC is a C language compiler tool under Linux, MySQL source compilation is written entirely by C and C + +, requires the installation of GCC4.4.6 or above version
4> Boost1.59.0
MySQL source used in C + + 's boost library, required to install boost1.59.0 or above version
5> bison2.1
Linux down-C + + syntax parser
6> ncurses
Character Terminal Processing Library
MySQL compilation installation