Step-by-Step Guide to Compile and Install MySQL 8.0 on CentOS 7
Learn how to compile MySQL 8.0 from source on CentOS 7, including installing dependencies, creating users, configuring build options, setting up systemd services, initializing the database, and securing the root account, with complete command examples and configuration file details.
1. Compile and Install MySQL 8.0
Version information
# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)Install dependency packages
yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel
rpm -qa | grep libaio
yum install libaio libaio-develDownload source package
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gzCreate MySQL user and data directories, then set permissions
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
mkdir -p /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql
chmod -R 755 /usr/local/mysql/
chmod -R 755 /data/mysql/Extract source and start installation
tar -zxf mysql-boost-8.0.12.tar.gzConfigure build options
cd mysql-8.0.12
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DWITH_BOOST=~/mysql-8.0.12/boost \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1Explanation of key CMake parameters
CMAKE_INSTALL_PREFIX : installation base directory
MYSQL_DATADIR : data directory
SYSCONFDIR : configuration file directory
MYSQL_TCP_PORT : listening port
WITH_BOOST : path to Boost library
DEFAULT_CHARSET : default character set
DEFAULT_COLLATION : default collation
ENABLED_LOCAL_INFILE : enable LOAD DATA INFILE
WITH_INNODB_MEMCACHED: build memcached pluginCompile and install
make && make installInitialize the database
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqlCreate the MySQL configuration file
cat > /etc/my.cnf <<EOF
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysqld]
server-id=1
port=3306
user=mysql
max_connections=200
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
pid-file=/data/mysql/mysql.pid
init-connect='SET NAMES utf8'
character-set-server=utf8
default-storage-engine=INNODB
log_error=/data/mysql/mysql-error.log
slow_query_log_file=/data/mysql/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=16M
EOFSet environment variables
echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
source /etc/profileConfigure startup script
cp ../mysql-8.0.12/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld startSystemd service file for CentOS 7
cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.target syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
LimitNOFILE=10000
Restart=always
Environment=MYSQLD_PARENT_PID=1Start MySQL service
systemctl start mysqld.serviceChange the root password (choose authentication plugin)
mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_password';Verify password field and authentication plugin
SELECT host, user, authentication_string, plugin FROM user;2. Install MySQL via YUM Repository
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum localinstall mysql80-community-release-el7-1.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
yum repolist all | grep mysql
yum install mysql-community-server
systemctl enable mysqld
systemctl start mysqld
netstat -lntup | grep 3306View the automatically generated temporary password
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -pChange the root password (must include upper‑case, lower‑case, digits and special characters)
ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]';
SELECT VERSION();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.
