MySQL 5.6 Binary Installation and Service Configuration on CentOS 7
System Preparation
Execute the following on a CentOS 7 host. First eliminate conflicts with the distribution’s default database packages:
yum -y remove mariadb*
Install the supporting libraries and build utilities required by the generic Linux binary:
yum -y install autoconf bison ncurses-devel libaio
Create an unprivileged account that will own the server processes:
groupadd dbgroup
useradd -g dbgroup -s /sbin/nologin dbadmin
Software Installation
Retrieve the official generic binary archive:
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
Extract the archive and establish a version-agnostic path:
tar -zxf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz -C /opt/
ln -s /opt/mysql-5.6.39-linux-glibc2.12-x86_64 /opt/mysql
Create the data and logging directories, then transfer ownership to the service account:
mkdir -p /data/mysql /var/log/mysqldb
chown -R dbadmin:dbgroup /opt/mysql /data/mysql /var/log/mysqldb
Server Configuration
Write the runtime options to /etc/my.cnf:
[client]
port = 3306
socket = /data/mysql/mysql.sock
default-character-set = utf8mb4
[mysqld]
user = dbadmin
port = 3306
socket = /data/mysql/mysql.sock
basedir = /opt/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysqld.pid
log-error = /var/log/mysqldb/error.log
bind-address = 0.0.0.0
skip-name-resolve
lower_case_table_names = 1
max_connections = 300
max_allowed_packet = 32M
default-storage-engine = InnoDB
character-set-server = utf8mb4
Data Directory Initialization
Bootstrpa the system tables:
cd /opt/mysql
./scripts/mysql_install_db --user=dbadmin --basedir=/opt/mysql --datadir=/data/mysql
Restrict access to the options file:
chown dbadmin:dbgroup /etc/my.cnf
chmod 640 /etc/my.cnf
Systemd Integration
Create the unit file at /usr/lib/systemd/system/mysqld.service:
[Unit]
Description=MySQL 5.6 Database Server
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/mysql/support-files/mysql.server start
ExecReload=/opt/mysql/support-files/mysql.server restart
ExecStop=/opt/mysql/support-files/mysql.server stop
PrivateTmp=true
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
Reload the systemd manager configuartion:
systemctl daemon-reload
Environment and Startup
Make the client binaries available to all users:
echo 'export PATH=/opt/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
Launch the server and configure it to start on boot:
systemctl start mysqld
systemctl enable mysqld