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:
- Version control: You can pin an exact 8.0.x minor release, making it easy to align with your application compatibility test results.
- Consolidated paths: Everything lives under a single prefix directory, so uninstalling, rolling back, or performing a canary upgrade only requires switching a symlink.
- 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 --versionand 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 3306shows it at a glance. - Hostname and hosts: Make sure
hostnameresolves 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:
/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.
# List existing related packagesdpkg -l | grep -Ei 'mysql|mariadb'# If there is output, run the cleanupsudo apt updatesudo systemctl stop mysql mariadb 2>/dev/null || truesudo apt purge -y 'mysql*' 'mariadb*'sudo apt autoremove -y# Remove leftover config and data directories (confirm there is no important data first)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. Create the versioned installation directorysudo mkdir -p /opt/mysql-8.0# 2. Extract and strip the top-level directorysudo tar -xJf /opt/soft/mysql-8.0.x-linux-glibc2.28-x86_64.tar.xz \-C /opt/mysql-8.0 --strip-components=1# 3. Create a unified entry symlinksudo ln -sfn /opt/mysql-8.0 /opt/mysql# 4. Create the runtime user and data directorysudo groupadd mysqlsudo useradd -r -g mysql -s /bin/false mysqlsudo 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”:
sudo chown -R root:root /opt/mysql-8.0sudo chown -R mysql:mysql /opt/mysql/datasudo 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:
# Option 1: Generate a temporary root password (check the log for it)sudo /opt/mysql/bin/mysqld --defaults-file=/opt/mysql/my.cnf \--initialize --user=mysql# Option 2: Initialize with an empty root password, which must be set immediatelysudo /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:
[mysqld]basedir=/opt/mysqldatadir=/opt/mysql/dataport=3306socket=/opt/mysql/run/mysql.sockpid-file=/opt/mysql/run/mysqld.pidlog-error=/opt/mysql/log/error.logcharacter-set-server=utf8mb4collation-server=utf8mb4_0900_ai_ci[client]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:
echo 'export PATH=/opt/mysql/bin:$PATH' | sudo tee /etc/profile.d/mysql.shsource /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:
# /etc/systemd/system/mysql.service[Unit]Description=MySQL Database ServerAfter=network.target[Service]User=mysqlGroup=mysqlType=notifyExecStart=/opt/mysql/bin/mysqld --defaults-file=/opt/mysql/my.cnfLimitNOFILE=65535Restart=on-failure[Install]WantedBy=multi-user.target
sudo systemctl daemon-reloadsudo systemctl enable --now mysqlsudo 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
mysql -uroot -p# If there is no initial password, press Enter to get in, then change it immediatelyALTER 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:
SHOW DATABASES;SELECT VERSION();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.
mysqldump -uroot -p --single-transaction \--default-character-set=utf8mb4 \--routines --triggers --events \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:
mysql -uroot -p -e "CREATE DATABASE IF NOT EXISTS your_db \DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"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.
