How to Manually Deploy MySQL 8.0 on Linux: A Complete Guide

    This guide walks through manually deploying MySQL 8.0 on Linux using the official Generic TAR archive. It covers environment checks, cleanup of previous installations, directory layout, permissions, initialization, configuration, systemd service management, password changes, data migration, and post-deployment hardening. You will end up with a MySQL instance that has a clear directory structure, restricted permissions, automatic startup, and a repeatable upgrade path. The same approach applies to MySQL 8.4 LTS, with only the downloaded archive changed.

    How to Manually Deploy MySQL 8.0 on Linux: A Complete Guide

    Why Choose Manual Deployment with the Generic Binary Package

    In most enterprise environments, there are two common ways to install a database: a one-command install through the system package manager, or downloading the official Generic TAR archive and deploying it manually. The first option is fast, but the version is constrained by the distribution repositories and the files are scattered across multiple directories, which makes troubleshooting less straightforward. The second option takes a few more steps but delivers three key benefits:

    1. Version control: You can pin an exact 8.0.x minor release, making it easy to align with your application compatibility test results.
    2. Consolidated paths: Everything lives under a single prefix directory, so uninstalling, rolling back, or performing a canary upgrade only requires switching a symlink.
    3. Environment decoupling: You are not tied to the build options of distribution repositories, so behavior stays more consistent when migrating across distributions.

    One thing to keep in mind: the 8.0 series is in the later stage of its lifecycle. If your scenario allows it, consider evaluating a long-term support release such as 8.4 LTS. The directory layout and process described here apply to both 8.0 and 8.4; you only need to swap the archive you download.

    Pre-Deployment Environment Checklist

    Confirm the fundamentals before you start, and you can avoid 80% of the rework later:

    • CPU architecture: Confirm whether it is x86-64 or ARM64; the archive type must match.
    • glibc version: The generic package has a minimum requirement for the base C library. Check your system version with ldd --version and pick an archive built against a version no higher than yours; on newer systems, just choose the package with the larger version number.
    • Port availability: Check whether the default 3306 is already in use; ss -lntp | grep 3306 shows it at a glance.
    • Hostname and hosts: Make sure hostname resolves to the local machine, otherwise initialization may fail due to name resolution errors.
    • Time synchronization: Enable a time synchronization service to avoid clock drift affecting replication or certificate validation.
    • Resource planning: Reserve enough space on the partition that will hold the data directory, and consider a separate disk or partition to make later expansion easier.

    Download the Archive and Upload It to the Target Host

    Go to the official database archive download page and filter by version, then operating system type (Linux - Generic), then architecture. Choose the Compressed TAR Archive (.tar.xz). If the target machine has no direct internet access, download it locally and upload it with a terminal file transfer tool, for example to:

    1. /opt/soft/mysql-8.0.x-linux-glibc2.28-x86_64.tar.xz

    After the upload, verify integrity first (compare against the officially published checksum) before moving on to installation. This step may look redundant, but in proxy or interrupted-transfer scenarios, a corrupted package is a common cause of initialization failures.

    Clean Up Leftovers to Avoid Version Conflicts

    If a database was ever installed on the machine (including community or forked implementations), you must clean it up thoroughly first. Otherwise you can end up with configuration files overwriting each other, incorrect ownership on the data directory, and service name conflicts.

    1. # List existing related packages
    2. dpkg -l | grep -Ei 'mysql|mariadb'
    3. # If there is output, run the cleanup
    4. sudo apt update
    5. sudo systemctl stop mysql mariadb 2>/dev/null || true
    6. sudo apt purge -y 'mysql*' 'mariadb*'
    7. sudo apt autoremove -y
    8. # Remove leftover config and data directories (confirm there is no important data first)
    9. sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql

    Debian-based systems use dpkg/apt; RHEL-based systems use rpm/yum/dnf. The idea is the same: stop the services, uninstall the packages, then remove the directories.

    Directory Layout and Extracting the Archive

    A “versioned prefix + unified symlink” structure is recommended. Upgrades only change where the symlink points, and a rollback just switches it back:

    1. # 1. Create the versioned installation directory
    2. sudo mkdir -p /opt/mysql-8.0
    3. # 2. Extract and strip the top-level directory
    4. sudo tar -xJf /opt/soft/mysql-8.0.x-linux-glibc2.28-x86_64.tar.xz \
    5. -C /opt/mysql-8.0 --strip-components=1
    6. # 3. Create a unified entry symlink
    7. sudo ln -sfn /opt/mysql-8.0 /opt/mysql
    8. # 4. Create the runtime user and data directory
    9. sudo groupadd mysql
    10. sudo useradd -r -g mysql -s /bin/false mysql
    11. sudo mkdir -p /opt/mysql/data

    Running the database as a system user (-r) with login disabled (-s /bin/false) is a security baseline requirement: the database process should not be able to log in interactively.

    Locking Down Permissions: The Principle of Least Privilege

    Permissions that are too broad let the database process read and write arbitrary files; permissions that are too narrow cause initialization to fail. The core rule is “read-only program directory, writable data directory”:

    1. sudo chown -R root:root /opt/mysql-8.0
    2. sudo chown -R mysql:mysql /opt/mysql/data
    3. sudo chmod 750 /opt/mysql/data

    In other words: the binaries and configuration files are owned by root and cannot be modified by regular users; the data directory is owned by the mysql user with mode 750, which prevents other users on the same host from snooping on data files.

    Initializing the Data Dictionary

    There are two initialization methods. For production, “initialize without a password and change it immediately” is preferred, to avoid leaking a temporary password through logs:

    1. # Option 1: Generate a temporary root password (check the log for it)
    2. sudo /opt/mysql/bin/mysqld --defaults-file=/opt/mysql/my.cnf \
    3. --initialize --user=mysql
    4. # Option 2: Initialize with an empty root password, which must be set immediately
    5. sudo /opt/mysql/bin/mysqld --initialize-insecure --user=mysql

    If initialization fails, look at the error log first (usually the .err file in the data directory). Common causes include a non-empty data directory, ownership that is not mysql, a glibc version that is too old, and missing dependency libraries such as libaio. Missing dependencies can be resolved by installing the common runtime libraries through the system package manager and retrying.

    Configuration File and Environment Variables

    Create a minimal working configuration that explicitly defines the paths, port, character set, and error log:

    1. [mysqld]
    2. basedir=/opt/mysql
    3. datadir=/opt/mysql/data
    4. port=3306
    5. socket=/opt/mysql/run/mysql.sock
    6. pid-file=/opt/mysql/run/mysqld.pid
    7. log-error=/opt/mysql/log/error.log
    8. character-set-server=utf8mb4
    9. collation-server=utf8mb4_0900_ai_ci
    10. [client]
    11. socket=/opt/mysql/run/mysql.sock

    Note that the run and log directories must be created in advance and given to the mysql user. Then configure the environment variables so the command line tools are directly callable:

    1. echo 'export PATH=/opt/mysql/bin:$PATH' | sudo tee /etc/profile.d/mysql.sh
    2. source /etc/profile.d/mysql.sh

    Managing Automatic Startup with systemd

    The manual mysqld_safe & approach does not survive a reboot. Handing the process to the init system gives you crash recovery and startup on boot:

    1. # /etc/systemd/system/mysql.service
    2. [Unit]
    3. Description=MySQL Database Server
    4. After=network.target
    5. [Service]
    6. User=mysql
    7. Group=mysql
    8. Type=notify
    9. ExecStart=/opt/mysql/bin/mysqld --defaults-file=/opt/mysql/my.cnf
    10. LimitNOFILE=65535
    11. Restart=on-failure
    12. [Install]
    13. WantedBy=multi-user.target
    1. sudo systemctl daemon-reload
    2. sudo systemctl enable --now mysql
    3. sudo systemctl status mysql

    If the status stays at activating, it is most likely a permissions issue on the socket/pid directory or a misspelled configuration option; work through them one by one against the error log.

    Logging In, Changing the Password, and Verifying

    1. mysql -uroot -p
    2. # If there is no initial password, press Enter to get in, then change it immediately
    3. ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourStrongPassw0rd!';

    MySQL 8.0 uses a strong password plugin by default, so weak passwords are rejected. Use a combination of uppercase and lowercase letters, digits, and symbols. After changing the password, log out and back in, then verify basic functionality:

    1. SHOW DATABASES;
    2. SELECT VERSION();
    3. SHOW VARIABLES LIKE 'character_set_server';

    If the system databases are listed and the version is returned, the instance is working.

    Data Migration: Export and Import

    Logical export (command line): Suitable for small to medium data volumes and cross-version migration.

    1. mysqldump -uroot -p --single-transaction \
    2. --default-character-set=utf8mb4 \
    3. --routines --triggers --events \
    4. your_db > /opt/soft/your_db.sql

    --single-transaction guarantees a consistent snapshot without blocking business traffic; --routines/--triggers/--events avoids missing stored procedures and scheduled events.

    Graphical import and export: When the data volume is large or you need to filter visually, you can use a general-purpose database management tool and follow the flow of “select connection, select database and tables, export as SQL or a custom format”. When exporting, remember to enable “include create statements” and “escape special characters”.

    Import:

    1. mysql -uroot -p -e "CREATE DATABASE IF NOT EXISTS your_db \
    2. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"
    3. mysql -uroot -p your_db < /opt/soft/your_db.sql

    After importing, always spot-check row counts and key table structures, and check whether the character set has degraded into garbled text.

    Hardening and Operations Recommendations Before Going Live

    • Network exposure: Listen only on internal addresses, restrict source ranges with a firewall, and never expose 3306 to the public internet.
    • Account governance: Remove anonymous accounts and test databases, create a dedicated account for the application with per-database grants, and disable remote root login.
    • Backup strategy: Combine logical and physical backups, run recovery drills regularly, and store backup files off-site.
    • Monitoring and alerting: Integrate with general-purpose monitoring, alerting, and logging services, and set thresholds for connection count, slow queries, buffer pool hit rate, and disk usage.
    • Upgrade path: Use symlink switching for canary upgrades, and complete a full backup and compatibility validation before upgrading.
    • Cloud alternative: If the team lacks a dedicated DBA, consider a managed database offering from a cloud provider, where the platform handles backups, patches, and high availability while the business side only focuses on connections and capacity planning.

    Quick Reference for Common Issues

    Symptom Common Cause How to Fix
    Initialization exits with an error Non-empty data directory or wrong ownership Clear the directory and run chown mysql:mysql
    Fails immediately on startup Misspelled configuration option or port in use Check error.log and use ss -lntp to check the port
    Missing dependency library Base runtime libraries not installed Install the common runtime libraries with the package manager
    Connection refused Not listening or blocked by a firewall Check the bind configuration and security group/firewall
    Garbled text after import Client character set mismatch Standardize on utf8mb4 and re-import

    Following the process above, you can end up with a MySQL 8.0 instance on any mainstream Linux distribution that has a clear directory layout, restricted permissions, automatic startup, and is both backup- and upgrade-friendly. Once you turn these steps into an internal standard operating procedure, delivering on a new version or a new machine takes only a dozen minutes.