Offline Installation of MySQL 5.7 on CentOS 7
Prepare Installation Package
The binary installation package for MySQL 5.7.20 can be downloaded via the following link. On a networked machine you can use wget for direct download. For offline target servers, download the file on a connected device first, then transfer it to the /mysql directory of your target system:
http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
Create Dedicated Service User
For production environments, its recommended to run MySQL with a dedicated unprivileged user and user group:
# Create mysql user group
groupadd mysql
# Create mysql user and assign to the new group
useradd -g mysql mysql -d /home/mysql
# Set login password for the new user
passwd mysql
Extract Installation Files
Extract the compressed archive to /usr/local and set correct permissions:
cd /usr/local/
tar -xzvf /mysql/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
# Rename directory for easier management
mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
# Change ownership to the mysql user
chown -R mysql:mysql mysql/
Generate Configuration File
Back up any existing system MySQL configuration, then create a new optimized configuration (pre-configured for Atlassian application use):
# Back up original configuration
mv /etc/my.cnf /etc/my.cnf.bak
# Open new configuration file for editing
vim /etc/my.cnf
Add the following content to the configuration file:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
default-storage-engine=INNODB
max_allowed_packet=256M
innodb_log_file_size=256M
character_set_server=utf8mb4
innodb_default_row_format=DYNAMIC
innodb_large_prefix=ON
innodb_file_format=Barracuda
transaction-isolation=READ-COMMITTED
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
Pre-Initialize Service Files and Database
Create required runtime files and set correct permissions before initializing the database:
# Create log file and set permissions
cd /var/log/
touch mysqld.log
chmod 777 mysqld.log
chown mysql:mysql mysqld.log
# Create PID directory and file
mkdir -p /var/run/mysqld
touch /var/run/mysqld/mysqld.pid
chmod 777 /var/run/mysqld
chown -R mysql:mysql /var/run/mysqld
# Initialize database system tables
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
After initialization completes, a random temporary password for the root user is logged to the error log. Retrieve this password for login:
grep 'temporary password' /var/log/mysqld.log
Start Service and Enable Auto-Start on Boot
Start the MySQL service and configure it to run automatically when the system starts:
# First-time startup from installation directory
/usr/local/mysql/support-files/mysql.server start
# Copy service script to system init directory
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
# Add execute permission for the service script
chmod +x /etc/rc.d/init.d/mysqld
# Register the service with system startup
chkconfig --add mysqld
# Confirm the service is registered correctly
chkconfig --list mysqld
# Start service via system service manager
service mysqld start
# Check service running status
service mysqld status
# Example restart command
service mysqld restart
Post-Install Configuration
Update the default root password and create required databases for your applications:
# Add soft link to make mysql command available globally
ln -s /usr/local/mysql/bin/mysql /usr/bin
# Log into MySQL as root
mysql -uroot -p
# Enter the temporary password you retrieved earlier when prompted
# Update root password to your custom password
set password for root@localhost=password("your_new_password");
# Create database for Jira (if needed)
CREATE DATABASE jira CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
# Create database for Confluence (if needed)
CREATE DATABASE confluence CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
exit;