Step-by-Step Guide to Installing MySQL 5.7 on Linux
This article provides a detailed, command-line tutorial for installing MySQL 5.7 on a Linux system, covering directory creation, downloading and extracting the binary package, user setup, initialization, configuration file adjustments, service startup, and password configuration.
1. Create the /usr/local/src directory mkdir /usr/local/src 2. Change to the newly created directory cd /usr/local/src 3. Download the MySQL 5.7 binary package
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz4. Extract the archive tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz 5. Move the extracted folder to /usr/local and rename it to mysql mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql 6. Switch to the MySQL installation directory cd /usr/local/mysql 7. Create a dedicated MySQL system user without shell access useradd -M -s /sbin/nologin mysql 8. Initialize the MySQL 5.7 data directory ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql Note: The initialization prints a temporary root password, e.g., %(K5e!*DHNhA.
2018-05-22T10:49:09.886451Z 1 [Note] A temporary password is generated for root@localhost: %(K5e!*DHNhAContinue with SSL key generation: ./bin/mysql_ssl_rsa_setup --datadir=/data/mysql 9. Copy the default configuration file and edit it cp ./support-files/my-default.cnf /etc/my.cnf Edit /etc/my.cnf (e.g., with vi) and set the commonly required options:
basedir = /usr/local/mysql // program path datadir = /data/mysql // data directory port = 3306 // listening port server_id = ... socket = /tmp/mysql.sock // socket file
10. Copy the startup script and adjust its parameters cp ./support-files/mysql.server /etc/init.d/mysqld Edit /etc/init.d/mysqld and set:
basedir=/usr/local/mysql // program path datadir=/data/mysql // data directory
11. Enable and start the MySQL service, then verify its status chkconfig --add mysqld // add to startup /etc/init.d/mysqld start // start service ps aux | grep mysqld // check process netstat -ntlp | grep 3306 // verify port listening
12. Set the root password
Log in with the temporary password: /usr/local/mysql/bin/mysql -uroot -p'%(K5e!*DHNhA' Then change the password: mysql> SET PASSWORD = PASSWORD('123456'); Finally, add MySQL binaries to the system PATH: vim /etc/profile Add the line export PATH=/usr/local/mysql/bin:$PATH and reload:
. /etc/profileSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
