Skip to main content

MySQL 8.4 Single Node

Server IPHost Role
192.168.10.2MySQL Server

MySQL Server

  1. Download the MySQL installation package

    wget https://pdpublic.mingdao.com/private-deployment/offline/common/mysql-8.4.10-linux-glibc2.17-x86_64.tar.xz
  2. Extract the package to the installation directory

    tar -xvf mysql-8.4.10-linux-glibc2.17-x86_64.tar.xz
    mv mysql-8.4.10-linux-glibc2.17-x86_64 /usr/local/mysql
  3. Create the MySQL user

    useradd -U -M -s /sbin/nologin mysql
  4. 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/
  5. Create the /etc/my.cnf configuration file

    cat > /etc/my.cnf <<'EOF'
    [mysqld]
    user = mysql
    basedir = /usr/local/mysql
    datadir = /data/mysql
    socket = /usr/local/mysql/mysqld.sock
    pid-file = /usr/local/mysql/mysqld.pid
    log-error = /data/logs/mysql/mysqld.log
    server-id = 1
    bind-address = 0.0.0.0
    port = 3306
    skip-name-resolve = ON
    max_connections = 5000
    character_set_server = utf8mb4
    collation_server = utf8mb4_0900_ai_ci
    default_storage_engine = InnoDB
    innodb_buffer_pool_size = 2G
    innodb_flush_log_at_trx_commit = 1
    slow_query_log = ON
    slow_query_log_file = /data/logs/mysql/mysql-slow.log
    long_query_time = 1
    log_bin = /data/mysql/mysql-bin
    sync_binlog = 1
    binlog_expire_logs_seconds = 2592000

    [client]
    port = 3306
    socket = /usr/local/mysql/mysqld.sock
    default-character-set = utf8mb4

    [mysql]
    default-character-set = utf8mb4
    EOF
  6. Configure the systemd management file

    cat > /etc/systemd/system/mysql.service <<'EOF'
    [Unit]
    Description=MySQL Database Server
    Documentation=man:mysqld(8) http://dev.mysql.com/doc/
    After=network.target
    Wants=network-online.target
    After=network-online.target

    [Service]
    Environment=MYSQLD_PARENT_PID=1
    User=mysql
    Group=mysql
    Type=forking
    PIDFile=/usr/local/mysql/mysqld.pid
    ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize
    ExecStop=/bin/kill -s SIGTERM $MAINPID
    LimitNOFILE=102400
    LimitMEMLOCK=infinity
    Restart=on-failure
    OOMScoreAdjust=-500
    TimeoutSec=0

    [Install]
    WantedBy=multi-user.target
    EOF
  7. Initialize MySQL

    /usr/local/mysql/bin/mysqld --initialize --datadir=/data/mysql/ --user=mysql --log-error=/data/logs/mysql/mysqld.log
  8. Start MySQL and enable it to start automatically at boot

    systemctl daemon-reload
    systemctl enable mysql
    systemctl start mysql
  9. 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';
    grant all privileges on *.* to 'root'@'%' with grant option;
    quit;
    • The root user password changed by the command is 123456; use a strong password in actual deployments.
    • If the password contains special characters, only - or _ are allowed. Do not use characters such as @ ! # & to avoid compatibility issues.
  10. Test the database connection with the newly configured password

    /usr/local/mysql/bin/mysql -h127.0.0.1 -uroot -p123456