MySQL 8.0 Single Node
Server IP | Host Role |
---|---|
192.168.10.2 | MySQL Server |
MySQL Server
-
Download the MySQL installation package
- Server can access the Internet
- Server cannot access the Internet
wget https://pdpublic.mingdao.com/private-deployment/offline/common/mysql-8.0.42-linux-glibc2.17-x86_64.tar.xz
# Download link for the MySQL installation package. After downloading, upload it to the deployment server.
https://pdpublic.mingdao.com/private-deployment/offline/common/mysql-8.0.42-linux-glibc2.17-x86_64.tar.xz -
Extract to the installation directory
tar -xvf mysql-8.0.42-linux-glibc2.17-x86_64.tar.xz
mv mysql-8.0.42-linux-glibc2.17-x86_64 /usr/local/mysql -
Create a MySQL user
useradd -U -M -s /sbin/nologin mysql
-
Create data and log directories and grant permissions
mkdir -p /data/mysql/ /data/logs/mysql
chown -R mysql:mysql /usr/local/mysql/ /data/mysql/ /data/logs/mysql/ -
Configure the systemd management file
cat > /etc/systemd/system/mysql.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/usr/local/mysql/mysqld.pid
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --log-error=/data/logs/mysql/mysqld.log --datadir=/data/mysql --socket=/usr/local/mysql/mysql.sock --character-set-server=utf8mb4 --pid-file=/usr/local/mysql/mysqld.pid --server-id=1 --log-bin=mysql-bin --max_connections=2000 --slow_query_log=1 --slow_query_log_file=/data/logs/mysql/mysql-slow.log
LimitNOFILE=102400
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
[Install]
WantedBy=multi-user.target
EOF -
Initialize
/usr/local/mysql/bin/mysqld --initialize --datadir=/data/mysql/ --user=mysql --log-error=/data/logs/mysql/mysqld.log
-
Start MySQL and add it to startup
systemctl daemon-reload
systemctl enable mysql
systemctl start mysql -
Change the MySQL password
/usr/local/mysql/bin/mysql -h127.0.0.1 -uroot -p$(grep 'temporary password' /data/logs/mysql/mysqld.log | awk '{print $NF}')
ALTER USER USER() IDENTIFIED BY '123456';
update mysql.user set host='%' where user='root';
FLUSH PRIVILEGES;
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit;- The root user's password changed in the command is
123456
; replace it during actual deployment.
- The root user's password changed in the command is