Installing and Configuring MySQL 8.0 on Linux Systems

Verify System Compatibility

Run the following command to confirm your Linux distribution and architecture:

hostnamectl

Check your installed glibc version to ensure compatibility with the MySQL 8.0 binary:

rpm -q glibc

Download Installation Package

Fetch the official MySQL 8.0 tar.xz archive matching your system architecture and glibc version from the MySQL developer portal. The xz-compressed package has a smaller file size compared to standard tar archives.

Extract Archive

Extract the downloaded package to the /usr/local directory and rename the extracted folder for easier access:

# Extract archive to target directory
tar -Jxf mysql-8.0*.tar.xz -C /usr/local/
# Rename extracted directory to standardized path
mv /usr/local/mysql-8.0*-linux-glibc* /usr/local/mysql

User and Directory Setup

Create a dedicated system user and group for running MySQL to avoid running the service as root:

# Create MySQL user group
groupadd mysql
# Create non-login system user assigned to the MySQL group
useradd -r -s /sbin/nologin -g mysql mysql
# Create required runtime, data, and log directories
mkdir -p /usr/local/mysql/{data,run,log}
# Assign directory ownership to MySQL user and group
chown -R mysql:mysql /usr/local/mysql
# Set appropriate directory permissions
chmod -R 750 /usr/local/mysql

Update Configuration File

Edit the global MySQL configuration file /etc/my.cnf with the following parameters:

[mysql]
default-character-set = utf8mb4
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/run/mysql.sock
pid-file = /usr/local/mysql/run/mysqld.pid
log-error = /usr/local/mysql/log/mysqld.log
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
symbolic-links = 0
max_connections = 200

[mysqld_safe]
!includedir /etc/my.cnf.d

Initialize MySQL Instance

Run the initialization command to set up the core MySQL data directory. Save the temporary root password printed in the command output for first-time login:

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Configure Environment Variables

Add the MySQL binary path to your system PATH to make MySQL commands accessible globally:

# Create dedicated profile script for MySQL path
echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
# Load the new path configuration
source /etc/profile.d/mysql.sh
# Verify installation
mysql -V

Manage MySQL Service

Start Service

Copy the bundled init script to the system init directory and start the MySQL service:

# Copy init script to system directory
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# Make init script executable
chmod +x /etc/init.d/mysqld
# Edit the init script to update the following parameters:
# basedir=/usr/local/mysql
# datadir=/usr/local/mysql/data

# Start MySQL service
service mysqld start

First-Time Login

Create a symlink for the MySQL socket file to avoid connection errors, then log in with the temporary root password:

ln -s /usr/local/mysql/run/mysql.sock /tmp/mysql.sock
mysql -u root -p

Reset Root Password

After logging in, reset the temporary root password to a secure value:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'SecureRootPass789!';

Enable Remote Access (Optional)

To allow the root user to connect from remote hosts, run the following commands:

USE mysql;
UPDATE user SET host = '%' WHERE user = 'root' AND host = 'localhost';
FLUSH PRIVILEGES;

Stop Service

To stop the running MySQL service:

service mysqld stop

Configure Auto-Start on Boot

Register the MySQL service to start automatically on system boot:

# Add MySQL to system service list
chkconfig --add mysqld
# Enable auto-start for runlevels 2-5
chkconfig mysqld on
# Verify auto-start status
systemctl is-enabled mysqld

Create New Database and User

To set up a dedicated database and user for application use:

# Create new database with utf8mb4 support
CREATE DATABASE application_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
# Create application user with remote access permission
CREATE USER 'app_user'@'%' IDENTIFIED BY 'AppUserPass123!';
# Grant full privileges on the application database to the user
GRANT ALL PRIVILEGES ON application_db.* TO 'app_user'@'%';
# Apply privilege changes
FLUSH PRIVILEGES;

Tags: MySQL Linux Administration Database Installation MySQL 8.0 Server Configuration

Posted on Tue, 03 Nov 2026 16:21:23 +0000 by bouba