Rate This Document
Findability
Accuracy
Completeness
Readability

Installing MySQL on x86 Servers

Install MySQL on two x86 servers. After the installation of the primary and secondary databases is complete, modify the MySQL configuration file and initialize the MySQL database again to facilitate primary/secondary deployment and data consistency check.

Select the MySQL version suitable for your case. The recommended version is 8.0.34 or later. This document uses MySQL 8.0.36 as an example.

  1. Install MySQL on two x86 servers. For details about how to install MySQL, see MySQL Installation Guide on the MySQL official website.
  2. Modify the MySQL configuration files of the two x86 servers.
    1. Delete the default MySQL configuration file /etc/my.cnf and create a new /etc/my.cnf file.
      rm -f /etc/my.cnf
      vi /etc/my.cnf
    2. Press i to enter the insert mode and add the following content to the file:
      [mysqld_safe]
      log-error=/data/mysql/log/mysql.log
      pid-file=/data/mysql/run/mysqld.pid
      [mysqldump]
      quick
      [mysql]
      no-auto-rehash
      [client]
      default-character-set=utf8
      [mysqld]
      basedir=/usr/local/mysql
      socket=/data/mysql/run/mysql.sock
      tmpdir=/data/mysql/tmp
      datadir=/data/mysql/data
      default_authentication_plugin=caching_sha2_password
      port=3306
      user=mysql
      server-id=1 # The server-id of the primary database is 1. The server-id of the secondary database 1 (x86) is 2.
      log-bin=/data/mysql/data/mysql-bin
      relay_log=/data/mysql/relaylog/relay-bin
      report_host=x.x.x.x # Change x.x.x.x to the actual IP address. In this document, the IP address of the primary database server is 192.168.0.1, and the IP address of the secondary database 1 (x86) server is 192.168.0.2.
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  3. Re-initialize and restart the MySQL service.
    systemctl stop mysqld
    mysqld --defaults-file=/etc/my.cnf --initialize # Record the initial password.
    mysqld --defaults-file=/etc/my.cnf &

    If MySQL is installed by compiling the source code, run the following commands to initialize, start, and stop the MySQL service.

    • Initialization:
      /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize # Record the initial password.
    • Start:
      /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    • Stop:
      /usr/local/mysql/bin/mysqladmin shutdown -uroot -p -S /data/mysql/run/mysql.sock # Enter the initial password.

    If MySQL is installed using an RPM package, run the following commands to initialize, start, and stop the MySQL service.

    • Initialization:
      /usr/sbin/mysqld --defaults-file=/etc/my.cnf --initialize # Record the initial password.
    • Start:
      /usr/sbin/mysqld --defaults-file=/etc/my.cnf &
    • Stop:
      /usr/bin/mysqladmin shutdown -uroot -p -S /data/mysql/run/mysql.sock # Enter the initial password.
  4. Log in to the MySQL database.
    mysql -uroot -p -S /data/mysql/run/mysql.sock # Enter the initial password.
    • If MySQL is installed by compiling the MySQL source code, run the following command to log in to the MySQL client.
      /usr/local/mysql/bin/mysql -uroot -p -S /data/mysql/run/mysql.sock # Enter the initial password.
    • If MySQL is installed using an RPM package, run the following command to log in to the MySQL client.
      /usr/bin/mysql -uroot -p -S /data/mysql/run/mysql.sock # Enter the initial password.
  5. Create a remote management user on the MySQL database client, for example, the user name and password are root and 123456, respectively. Grant all database permissions to the root user, and exit the database.
    alter user 'root'@'localhost' identified by "123456";
    create user 'root'@'%' identified by '123456';
    grant all privileges on *.* to 'root'@'%';
    flush privileges;
    exit

    The database user name and password in this example are only for reference. Set them as required in your case.