Mysql Series II: Centos7.4 installation mysql5.7.28 source

This article is a blog Mysql Series II: Centos7.4 installation mysql5.7.28 source

There are a variety of methods to install mysql to Centos7 for example, the official website can download the compiled binary code installed, you can download the official website rpm package yum install rpm package to install, In this paper we introduce official website to download the source code to compile installation.

According to a series Mysql download the source code, we began to install mysql source, the installation method I hope you will read the document from the official website, to learn the essence, and the order is not the only method of installation, the following reference.

Basic environment:

yum install -y ntp wget curl lrzsz vim sysstat iftop pcre pcre-devel openssl openssl-devel

Compile and install environment:

yum -y install wget gcc gcc-c++ cmake openssl-devel ncurses-devel zlib-devel

Official website downloading codecs:

mysql-5.7.28.tar.gz和mysql-boost-5.7.28.tar.gz
cd /data/app_install/package
 tar zxvf mysql-5.7.28.tar.gz 
mkdir mysql-boost
tar zxvf mysql-boost-5.7.28.tar.gz -C mysql-boost

Create a mysql user:

groupadd mysql 
useradd  -g mysql -s /sbin/nologin -d /data/app_install/mysql_3306 mysql

Create a mysql Related Category:

mkdir -p /data/logs/mysql_3306                            日志目录
mkdir -p /data/app_install/mysql_3306                 安装目录
mkdir -p /data/app_install/mysql_3306/conf         my.cnf配置文件目录
mkdir -p /data/app_install/mysql_3306/tmp          mysql.sock目录
mkdir -p /data/data/data_mysql                            数据库文件目录

Compile configuration:

cmake . 
-DCMAKE_INSTALL_PREFIX=/data/app_install/mysql_3306 
-DMYSQL_DATADIR=/data/data/data_mysql 
-DWITH_BOOST=/data/app_install/package/mysql-boost/mysql-5.7.28/boost/boost_1_59_0 
-DSYSCONFDIR=/data/app_install/mysql_3306/conf 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_PARTITION_STORAGE_ENGINE=1 
-DWITH_FEDERATED_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_MYISAM_STORAGE_ENGINE=1 
-DENABLED_LOCAL_INFILE=1 
-DENABLE_DTRACE=0 
-DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci 
-DWITH_EMBEDDED_SERVER=1

Compile:

make

installation:

make install

Profiles:

cd /data/app_install/mysql_3306/conf
vim my.cnf

[client]
port = 3306
socket = /data/app_install/mysql_3306/tmp/mysql.sock
[mysqld]
port = 3306
socket =  /data/app_install/mysql_3306/tmp/mysql.sock
basedir = /data/app_install/mysql_3306
datadir = /data/data/data_mysql
pid-file = /data/app_install/mysql_3306/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
back_log = 300
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_rnd_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/logs/mysql_3306/mysqld-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/logs/mysql_3306/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 2048M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
default-time-zone = '+08:00'
interactive_timeout = 28800
wait_timeout = 86400
sql-mode= NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]
log-error = /data/logs/mysql_3306/mysqld_safe-error.log
pid-file = /data/app_install/mysql_3306/mysql.pid

Startup file:

cp /data/app_install/mysql_3306/support-files/mysql.server /etc/init.d/mysqld

Permissions:

chown -R mysql:mysql /data/app_install/mysql_3306/
chown -R mysql:mysql /data/data/data_mysql/
chown -R mysql:mysql /data/logs/mysql_3306/

Environment variables:

mkdir /data/env
cd /data/env
vim mysql.env
export PATH=$PATH:/data/app_install/mysql_3306/bin
vim /etc/profile
source /data/env/mysql.env

Initialize the database:
-initialize indicates the default generate a random secure passwords, -initialize-insecure said they did not generate a password, you do not want to find and use a random password can be initialized as follows in the log, after the initial boot password security in

mysqld --defaults-file=/data/app_install/mysql_3306/conf/my.cnf --user=mysql --initialize-insecure

Start mysql:

/etc/init.d/mysqld start

When you start experiencing log path does not exist or permission problem, re-create and assign mysql: mysql privileges can also experience a Starting MySQL ERROR The server quit without updating PID file (/data/app_install/mysql_3306/mysql.pid.! .) is the authority, all directory files involved in addition to the boot files require mysql: mysql permission to
attempt the landing:
Mysql Series II: Centos7.4 installation mysql5.7.28 source

No password is required to log

Security initial boot:
When you use this feature, mysql process need to be online to use mysql_secure_installation command for secure initial boot
Mysql Series II: Centos7.4 installation mysql5.7.28 source

After setting a new password to login again.
Setup program from the start:

chkconfig --add mysqld
chkconfig mysqld on

service mysqld start
service mysqld stop
service mysqld restart

In fact Centos7 ready for service management and support self-starting, mysql with systemd can, for example, that use source version of the installation need to add items to compile -DWITH_SYSTEMD = 1, configure /etc/systemd/system/mysqld.service.ddirectory name from a file, and then based on the actual describes the following situation:

[Service]
LimitNOFILE=*`max_open_files`*
PIDFile=*`/path/to/pid/file`*
Nice=*`nice_level`*
LimitCore=*`core_file_limit`*
Environment="LD_PRELOAD=*`/path/to/malloc/library`*"
Environment="TZ=*`time_zone_setting`*"

againsystemctl daemon-reload

Known official website to download the source code and installation support chkconfig + service systemd + systemctl perform service configuration and management, we need to manually step by step practice, to understand the whole process and the principle of great help.

If the official website to download the compiled binary installation you can only use chkconfig + service and systemd + systemctl perform service configuration and management, if it is the official website to download the rpm package yum install directly can systemd + systemctl perform service configuration and management.

After the installation process can be packaged and compiled files into automated installation scripts, one-click install mysql database from scratch every time manually configured to compile province.

We will in the next section describes some simple practical mysql, some operations frequently used commands actual combat.

Guess you like

Origin blog.51cto.com/7142665/2448404
Recommended