Install MySQL 5.7.13
Install MySQL 5.7.13
I. brief introduction:
MySQL 5.7 main features:
1. Native support for Systemd
2. Better performance: better optimization for multicore CPU, solid state disk and lock
3. Better lnnoDB storage engine
4. More robust replication: replication brings a solution that does not lose data at all, and traditional financial customers can also choose to use MySQL databases.
5. Master-slave replication with multi-thread is already supported in MySQL-5.6.3 and above.
6. Add sys library: this will be the most ordinary library accessed by DBA in the future.
Second, install MySQL 5.7.13
System environment: Centos 7.2x86_64
1. Prepare before installation:
Since mariadb-libs is installed by default in Centos 7.2, uninstall it first.
[root@localhost ~] # rpm-aq | grep mariadb
Mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@localhost] # rpm-e mariadb-libs-- nodeps
2. Install related dependency packages
Prepare the following installation packages
Bison-3.0.4.tar.gz cmake-3.5.2.tar.gz mysql-5.7.13.tar.gz
Boost_1_59_0.tar.gz ncurses-5.9.tar.gz
Note: the role of related dependency packages
# cmake: since the regular configure compilation method has been deprecated from the MySQL5.5 version, a cmake compiler is required to set the compilation parameters of mysql. (e.g. installation directory, data storage directory, character encoding, sorting rules, etc.)
# boost: starting with MySQL5.7.5, the Boost library is required. C++ 's Boost library is used in the mysql source code, so Boost1.59.0 or above is required.
# GCC: this is the C language compilation tool under Linux. MySQL source code compilation is written entirely in C and C++. GCC is required.
Under # bison:Linux, Candlestick + parser.
# ncurses: character terminal processing library.
1) install cmake
[root@localhost ~] # tar zxf cmake-3.5.2.tar.gz
[root@localhost ~] # cd cmake-3.5.2/
[root@localhost cmake-3.5.2] #. / bootstrap
[root@localhost cmake-3.5.2] # gmake & & gmake install
2) View the cmake version:
3) install ncurses
[root@localhost ~] # tar zxf ncurses-5.9.tar.gz
[root@localhost ~] # cd ncurses-5.9/
[root@localhost ncurses-5.9] # / configure & & make & & make install
4) install bison
[root@localhost ~] # tar zxf bison-3.0.4.tar.gz
[root@localhost ~] # cd bison-3.0.4/
[root@localhost bison-3.0.4] # / configure & & make & & make install
5) install boost
[root@localhost ~] # tar zxf boost_1_59_0.tar.gz
[root@localhost ~] # mv boost_1_59_0 / usr/local/boost
6) create mysql users and user groups and directories
[root@localhost] # groupadd-r mysql
[root@localhost] # useradd-r-g mysql-s / bin/false-M mysql
[root@localhost] # mkdir-p / usr/local/mysql/data
3. Compile and install MySQL
Decompress mysql source code packet
[root@localhost ~] # tar zxf mysql-5.7.13.tar.gz
[root@localhost ~] # cd mysql-5.7.13/
Execute the cmake command for pre-compilation configuration
[root@localhost mysql-5.7.13] # cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/usr/local/mysql/data-DSYSCONFDIR=/etc-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DEXTRA_CHARSETS=all-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock-DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_PARTITION_STORAGE_ENGINE=1-DWITH_SYSTEMD=1-DWITH_BOOST=/usr/local/boost
Configuration explanation:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql # # MySQL installation root directory
-DMYSQL_DATADIR=/usr/local/mysql/data # # MySQL database file storage directory
-DSYSCONFDIR=/etc # # the directory where the MySQL configuration file is located
-DDEFAULT_CHARSET=utf8 # # set the default character set of Mysql to utf-8
-DDEFAULT_COLLATION=utf8_general_ci # # set default character set alignment rules
-DEXTRA_CHARSETS=all # # enables MySQL to support all extended characters
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock # # specify the mysql.sock location
-DWITH_MYISAM_STORAGE_ENGINE=1 # # add MYISAM engine support
-DWITH_INNOBASE_STORAGE_ENGINE=1 # # add lnnoDB engine support
-DWITH_ARCHIVE_STORAGE_ENGINE=1 # # add ARCHIVE engine support
-DWITH_PARTITION_STORAGE_ENGINE=1 # # installation supports database partitioning
-DWITH_SYSTEMD=1 # # you can use systemd to control mysql services
-DWITH_BOOST=/usr/local/boost # # points to the directory where the boost library is located
Start compilation and compilation installation
[root@localhost mysql-5.7.13] # make & & make install
Ways to speed up compilation:
[root@localhost mysql-5.7.13] # make-j $(grep processor / proc/cpuinfo | wc-l) & & make install
-j: parameter specifies the number of threads at compile time according to the number of CPU cores, which can speed up the compilation (default is 1 thread)
To rerun the cmake configuration, you need to delete the CMakeCache.txt file:
[root@localhost mysql-5.7.13] # make clean
[root@localhost mysql-5.7.13] # rm-f CMakeCache.txt
Optimize the execution path of MySQL
[root@localhost mysql-5.7.13] # echo "export PATH=$PATH:/usr/local/mysql/bin" > > / etc/profile
[root@localhost mysql-5.7.13] # source / etc/profile
4. Set permissions and initialize MySQL system authorization table
[root@localhost ~] # cd / usr/local/mysql/
[root@localhost mysql] # chown-R mysql:mysql.
[root@localhost mysql] # bin/mysqld-initialize-user=mysql-basedir=/usr/local-datadir=/usr/local/mysql/data
When initializing the operating system with root, add the-- user=mysql parameter to generate a random password. (remember to use it when logging in)
5. Create a configuration file
[root@localhost mysql] # cd support-files/
[root@localhost support-files] # cp my-default.cnf / etc/my.cnf
[root@localhost ~] # vim / etc/my.cnf # # add the following under [mysqld]
Basedir = / usr/local/mysql
Datadir = / usr/local/mysql/data
Port = 3306
Server_id = 1
Socket = / usr/local/mysql/mysql.sock
Log-error = / usr/local/mysql/data/mysqld.err
6. Configure mysql to start automatically
[root@localhost ~] # cp / usr/local/mysql/usr/lib/systemd/system/mysqld.service / usr/lib/systemd/system/
Because mysqld.service assigns the default pid file to the / var/run/mysqld directory without creating a directory in advance, starting mysql will fail at this time. Two solutions:
The first method: create the / var/run/mysqld directory and set the master to mysql
Root@localhost ~] # mkdir / var/run/mysqld
[root@localhost] # chown-R mysql:mysql / var/run/mysqld/
The second method: modify / usr/lib/system/system/mysqld.service
[root@localhost ~] # vim / usr/lib/systemd/system/mysqld.service
[root@localhost ~] # systemctl daemon-reload
Start the mysql service
[root@localhost ~] # systemctl start mysqld.service
[root@localhost ~] # systemctl status mysqld.service
View port number
[root@localhost ~] # netstat-anpt | grep mysqld
6. Set the database administrator user root password
[root@localhost] # mysqladmin-uroot-packs, hJs, VMOs, 9vQ, Q'password 123.com
Note: enter the random password generated during initialization in the-p option here
Access to MySQL database
[root@localhost] # mysql-u root-p
-- MySQL 5.7.13 installation is complete at this point