Detailed explanation of how to install mysql5.7.16 from source code in centos7 environment

Detailed explanation of how to install mysql5.7.16 from source code in centos7 environment

This article describes how to install mysql5.7.16 from source code in centos7 environment. Share with you for your reference, the details are as follows:

1. Download the source package

Download mysql source package

http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.16.tar.gz

2. Installation Agreement:

Username: mysql
Installation directory: /data/mysql
Database directory: /data/mysql/data

3. Installation Preparation

1. Add users

> useradd -s /sbin/nologin mysql

2. Create a directory

> mkdir /data/mysql

3. Change the directory owner and owner

> chown -R mysql:mysql /data/mysql

4. Install the files required for editing

> yum install gcc gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel

(*MySQL 5.7.5 and above versions require boost to be installed)

> yum install boost boost-devel

5. Unzip the source package

> tar -xf mysql-5.7.16.tar.gz

4. Compile and install

> cd /data/mysql-5.7.16
>cmake \
-DMYSQL_USER=mysql \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DSYSCONFDIR=/data/mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DINSTALL_PLUGINDIR=/data/mysql/plugin \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-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=/usr/local/boost

(*Note, if an error occurs, delete CMakeCache.txt and re-run the configuration)

The explanation of the above parameters is as follows:

#mysql username -DMYSQL_USER=mysql
#Installation path -DCMAKE_INSTALL_PREFIX=/data/mysql
#Data file storage location -DMYSQL_DATADIR=/data/mysql/data
#my.cnf path -DSYSCONFDIR=/data/mysql
#Support MyIASM engine - DWITH_MYISAM_STORAGE_ENGINE=1
#Support InnoDB engine - DWITH_INNOBASE_STORAGE_ENGINE=1
#Support Memory Engine - DWITH_MEMORY_STORAGE_ENGINE=1
#Plugin file and configuration path-DINSTALL_PLUGINDIR=/data/mysql/plugin
#Shortcut key function (I haven't used it)
-DWITH_READLINE=1
#Connect to the database socket path -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
#Port - DMYSQL_TCP_PORT=3306
#Allow importing data from local - DENABLED_LOCAL_INFILE=1
#Install support for database partitioning - DWITH_PARTITION_STORAGE_ENGINE=1
#Install all character sets -DEXTRA_CHARSETS=all
#Default character - DDEFAULT_CHARSET=utf8
#Check character -DDEFAULT_COLLATION=utf8_general_ci
# will automatically download boost
-DDOWNLOAD_BOOST=1
#Specify the boost directory -DWITH_BOOST=/usr/local/boost

Compile and install

> make && make install

Copy the configuration file

> cp /data/mysql/support-files/my-default.cnf /data/mysql/my.cnf

Initialize the database

> /data/mysql/bin/mysqld \
--defaults-file=/data/mysql/my.cnf \
--initialize \
--user=mysql \
--basedir=/data/mysql \
--datadir=/data/mysql/data \

If the following message appears:

unknown variable 'defaults-file=/data/mysql/my.cnf'

Please make sure that --defaults-file configuration option comes first.

If the following message appears:

[ERROR] --initialize specified but the data directory has files in it. Aborting.

Please ensure that your datadir directory is empty and delete any files if they exist.

The MySQL 5.7 version will randomly generate a root password when installed with --initialize, so be sure to save it.

If you want to generate an empty password, use the --initialize-insecure option.

Change the owner of the mysql directory

> chown -R mysql:mysql /data/mysql

5. Configure the MySQL configuration file my.cnf

Since we set the configuration file directory of MySQL to /data/mysql when compiling and installing it, delete /etc/my.cnf .

So as not to be affected.

> rm -rf /etc/my.cnf
> vi /data/mysql/my.cnf

The configuration is as follows:

[client]
default-character-set = utf8
port = 3306
socket = /data/mysql/mysql.sock
[mysql]
default-character-set = utf8
[mysqld]
skip-name-resolve
basedir = /data/mysql
datadir = /data/mysql/data
port = 3306
server_id = 10
socket = /data/mysql/mysql.sock
character-set-server = utf8
max_connections = 200
default-storage-engine = INNODB
log-bin=mysql-bin

Add startup for mysql

> cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
> chmod 755 /etc/init.d/mysqld
> chkconfig --add mysqld

Start mysql service

> service mysqld start

Add environment variables for mysql

> echo "export PATH=/data/mysql/bin/:$PATH" >> /etc/profile
> source /etc/profile

Log in to mysql with the password saved above to change the root password

>mysql -uroot -p
> set password=password('123456');
> alter user 'root'@'localhost' password expire never;
> flush privileges;

Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL common functions summary", "MySQL log operation skills", "MySQL transaction operation skills summary", "MySQL stored procedure skills" and "MySQL database lock related skills summary"

I hope this article will be helpful to everyone's MySQL database design.

You may also be interested in:
  • How to install jdk1.8.0_151 and mysql5.6.38 in centos7.2.1511
  • How to install mysql5.6 on centos7
  • Centos7 install mysql5.6.29 shell script
  • How to install and modify the initial password of mysql5.7.18 under Centos7.3
  • Centos7 installation and configuration of Mysql5.7
  • Tutorial on installing lnmp using yum on centos7 (linux+nginx+php7.1+mysql5.7)
  • Detailed steps to install Mysql5.7.19 using yum on Centos7
  • Detailed tutorial on installing Mysql5.7.19 on Centos7 under Linux
  • Alibaba Cloud Centos7.3 installation mysql5.7.18 rpm installation tutorial
  • Installation and configuration code of apache, php7 and mysql5.7 in CentOS7 server
  • CentOS7 uses rpm to install MySQL 5.7 tutorial diagram
  • Detailed explanation of how to install mysql5.6 from binary installation package in centos7 environment

<<:  Share MySql8.0.19 installation pit record

>>:  An article to understand the use of proxies in JavaScript

Recommend

Teach you how to use MySQL8 recursive method

I have previously written an article about recurs...

HTML table tag tutorial (35): cross-column attribute COLSPAN

In a complex table structure, some cells span mul...

HTML head tag detailed introduction

There are many tags and elements in the HTML head ...

HTML+CSS+JavaScript to achieve list loop scrolling example code

Description: Set a timer to replace the content of...

Summary of methods for finding and deleting duplicate data in MySQL tables

Sometimes we save a lot of duplicate data in the ...

Summary of some common methods of JavaScript array

Table of contents 1. How to create an array in Ja...

How to shut down/restart/start nginx

closure service nginx stop systemctl stop nginx s...

Linux Cron scheduled execution of PHP code with parameters

1. Still use PHP script to execute. Command line ...

Detailed explanation of the role of explain in MySQL

1. MYSQL index Index: A data structure that helps...

In-depth understanding of javascript class array

js array is probably familiar to everyone, becaus...

Analysis of common usage examples of MySQL process functions

This article uses examples to illustrate the comm...

MySQL advanced learning index advantages and disadvantages and rules of use

1. Advantages and Disadvantages of Indexes Advant...

Summary of JavaScript JSON.stringify() usage

Table of contents 1. Usage 1. Basic usage 2. The ...

Installation method of MySQL 5.7.18 decompressed version under Win7x64

Related reading: Solve the problem that the servi...