1. apt install libncurses5
    2. groupadd mysql
    3. useradd -r -g mysql -s /bin/false mysql
    4. cd /usr/local
    5. # 将二进制包放进该目录
    6. tar xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
    7. ln -s mysql-8.0.28-linux-glibc2.12-x86_64 mysql
    8. cd mysql
    9. mkdir mysql-files
    10. chown mysql:mysql mysql-files
    11. chmod 750 mysql-files
    12. bin/mysqld --initialize --user=mysql #初始化mysql会显示root临时密码
    13. bin/mysql_ssl_rsa_setup
    14. bin/mysqld_safe --user=mysql &
    15. cp support-files/mysql.server /etc/init.d/mysql.server
    16. vim /usr/lib/systemd/system/mysql.service
    17. vim /etc/my.cnf
    18. chmod -R 777 /var/log
    19. systemctl enable mysql
    20. systemctl start mysql
    21. vim /etc/profile # >>export PATH=/usr/local/mysql/bin:$PATH
    1. [Unit]
    2. Description=MySQL Server
    3. Documentation=man:mysqld(8)
    4. Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    5. After=network.target
    6. After=syslog.target
    7. [Install]
    8. WantedBy=multi-user.target
    9. [Service]
    10. User=mysql
    11. Group=mysql
    12. ExecStart=/usr/local/mysql/bin/mysqld
    13. --defaults-file=/etc/my.cnf
    14. LimitNOFILE = 5000
    [mysqld]
    port=3306
    basedir=/usr/local/mysql/
    datadir=/usr/local/mysql/data/
    character-set-server=utf8mb4
    socket=/tmp/mysql.sock
    log-error=/var/log/mysql-error.log
    log-bin=mysql-bin
    [mysql]
    default-character-set=utf8
    socket=/tmp/mysql.sock
    [client]
    port=3306
    default-character-set=utf8
    socket=/tmp/mysql.sock
    

    修改root密码:
    mysqladmin -uroot -p

    APT安装MySQL后获取临时账户密码:
    sudo cat /etc/mysql/debian.cnf

    YUM安装后MySQL获取root临时密码:
    sudo grep 'temporary password' /var/log/mysqld.log

    mysql> use mysql;
    mysql> update mysql.user set authentication_string='',plugin='mysql_native_password' where user='root';
    mysql> flush privileges;
    
    mysql> SHOW VARIABLES LIKE 'validate_password%';
    mysql(5.7)> set global validate_password_policy=0;
    mysql(5.7)> set global validate_password_length=1;
    mysql(8.0)> set global validate_password.policy=0;
    mysql(8.0)> set global validate_password.length=1;