Databases 5 min read

Step-by-Step Guide to Install and Initialize MySQL 8.0.17 on Linux

This tutorial walks through extracting the MySQL 8.0.17 package, creating required directories and users, configuring my.cnf, initializing the data directory, setting up startup scripts, adding MySQL to the system PATH, starting the service, and securing the root password on a Linux host.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Step-by-Step Guide to Install and Initialize MySQL 8.0.17 on Linux

1. Extract MySQL package : tar -zxvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.gz The extraction creates the directory mysql-8.0.17-linux-glibc2.12-x86_64/ with binaries such as mysql, mysqld, and utility tools.

2. Move to installation path : mv mysql-8.0.17-linux-glibc2.12-x86_64 /usr/local/mysql 3. Create data directories and grant permissions :

mkdir -p /data/mysql/mysql
mkdir -p /data/mysql/logs
useradd mysql
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/

4. Modify configuration file : Backup the original file and edit /etc/my.cnf (e.g., set server_id=100).

cp /etc/my.cnf /etc/my.cnf.bak2021
vim /etc/my.cnf

5. Initialize the data directory (first attempt may fail, so remove old directories and retry):

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

If errors occur, delete the existing logs and mysql folders, recreate them, and re‑run the initialization command with appropriate paths:

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

6. Configure startup script : copy the provided server script and make it executable.

vim /usr/local/mysql/support-files/mysql.server
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 775 /etc/init.d/mysqld

7. Add MySQL binaries to the system PATH and reload the profile: vim /etc/profile (add export PATH=$PATH:/usr/local/mysql/bin) source /etc/profile 8. Start MySQL service : /etc/init.d/mysqld start The output should indicate Starting MySQL.... SUCCESS! 9. Retrieve the temporary root password from the MySQL error log (shown in the accompanying screenshot) and log in: mysql -u root -p 10. Change the root password and verify users: ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; Check existing accounts: SELECT user,host FROM mysql.user; Additional resources are linked at the end of the original article for MySQL backup, common commands, and binary log usage.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseLinuxmysqlInstallationInitializationstartup
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.