Step-by-Step Guide to Install MySQL 5.7 on CentOS 6
This tutorial walks through downloading MySQL 5.7, creating a dedicated user and group, extracting the package, initializing the database with the new mysqld --initialize command, configuring my.cnf, setting up service auto‑start, and securing the root account and remote access on a CentOS 6 server.
Author: 云上之山 Source: http://blog.csdn.net/nengyu/article/details/51615836
1. Download MySQL 5.7.13
Obtain the tar.gz package from the official MySQL download page.
2. Create MySQL user and group, and data directory
# groupadd mysql
# useradd -g mysql -d /opt/my/mysql mysql
# mkdir /opt/my/mysql/data3. Extract the package
# tar -xzvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz
# mv mysql-5.7.9-linux-glibc2.5-x86_64 mysql4. Initialize the database
MySQL 5.7 deprecates mysql_install_db; use mysqld --initialize instead.
# ./bin/mysqld --user=mysql --basedir=/opt/my/mysql --datadir=/opt/my/mysql/data --initializeIf the data directory already contains files, the command will fail; remove the contents and re‑run.
# cd /opt/my/mysql/data
# rm -fr *5. Start the MySQL service
# cd /home/mysql
# ./support-files/mysql.server start
Starting MySQL.. SUCCESS!If the service fails, edit /support-files/mysql.server to set the correct basedir and datadir paths.
6. Create a symbolic link
# ln -s /opt/my/mysql/bin/mysql /usr/bin/mysql7. Configure my.cnf
# mv /etc/my.cnf /etc/my.cnf.bak
# cp my-default.cnf /etc/my.cnf
# vim /etc/my.cnf
[mysqld]
basedir = /opt/my/mysql
datadir = /home/mysql/data
character_set_server=utf8
init_connect='SET NAMES utf8'
[client]
default-character-set=utf88. Enable automatic start on boot
# cp /opt/my/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on9. Manage the MySQL service
# service mysqld start
# service mysqld restart
# service mysqld stop10. Set the root password
Stop the service, then initialize again to obtain the temporary password, and change it with mysqladmin or SQL statements.
# service mysqld stop
# ./bin/mysqld --initialize # generates temporary password
# mysqladmin -u root -p'temporary' password 'new_password'11. Grant remote access
Example grant statement:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'new_password' WITH GRANT OPTION;
FLUSH PRIVILEGES;After completing these steps, MySQL 5.7 is installed, configured, and ready for use on CentOS 6.
Signed-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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
