Install mysql on Alibaba Cloud

1. Download the Yum warehouse of Mysql
        https://dev.mysql.com/downloads/repo/yum/

 2. Drag the file downloaded in the first step into the server and install it:

     yum localinstall mysql80-community-release-el7-3.noarch.rpm

3. Check whether the source is installed successfully

     yum repolist enabled | grep "mysql.-community."

4. Select the version

    vi /etc/yum.repos.d/mysql-community.repo

5. Installation

    yum install mysql-community-server

6. Start mysql

    systemctl start mysqld

If the following error is reported at startup, you need to delete the mysql directory under the /var/lib directory, because the target path already exists /var/lib/mysql/, resulting in failure to initialize, just restart after deleting:

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2020-12-12 16:53:16 CST; 1min 48s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 18399 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 18373 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 18399 (code=exited, status=1/FAILURE)
   Status: "Server startup in progress"
    Error: 2 (No such file or directory)

Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.153655Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or e...re release.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.155254Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22) starting as process 18399
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.167524Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.167640Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.167694Z 0 [ERROR] [MY-010119] [Server] Aborting
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z mysqld[18399]: 2020-12-12T08:53:16.168284Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.22)  MySQL C...rver - GPL.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: Failed to start MySQL Server.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: Unit mysqld.service entered failed state.
Dec 12 16:53:16 iZ2zebcdfzd6516iqs3di2Z systemd[1]: mysqld.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

7. Set the boot to start automatically

     systemctl enable mysqld

    systemctl daemon-reload

 8. Set the mysql password:

    It is said on the Internet that there are passwords in /var/log/mysqld.log and /var/log/mysql.log, but there is nothing in them after entering.

   So by modifying the mysql configuration file, let him skip the password and use root to enter the database

     ①Find /etc/my.cnf, edit: vim /etc/my.cnf

     ②Add a sentence of skip-grant-tables under the [mysqld] label or at the bottom of the file

     ③esc to exit the editor, then enter: wq to save and exit, then restart the server service mysqld restart to make the modification take effect

    ④ mysql -u root can directly enter the database.

    ⑤ Then change the password. It is better to set the password to be more complex. Suggestion: uppercase letters + lowercase letters + symbols. Otherwise, mysql will report an error and let you change to comply with the mysql security policy, or you can also modify the mysql security policy

          mysql> USE mysql;             

          Use the command to check whether the validate_password password validation plugin is installed: mysql> SHOW VARIABLES LIKE 'validate_password%';

         MySQL 8.0 adjusts password validation rules:

          mysql> set global validate_password.policy=0;

          mysql> set global validate_password.length=1;

       Solution 1: Restrict local login

                  ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
                  flush privileges;

      Solution 2: Any IP can be used to log in with a third-party client

ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER;    #修改root的密码与加密方式
use mysql;   #切换到mysql库
update user set host='%' where user = 'root';   #更改可以登录的IP为任意IP
flush privileges;    #刷新权限
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码'; #再次更改root用户密码,使其可以在任意IP访问
flush privileges;    #刷新权限

                mysql> quit

   ⑥ After changing the password, change the configuration file back, just delete the added sentence, and then restart the server service mysqld restart

   ⑦ Then you can use mysql -uroot -p to enter your new password to enter

Summary of the problem: By looking at the comparison of the MySQL5.7 and MySQL8.0 password verification plug-ins, we can see that the variable names are different in the two versions. (*_password_policy and *_password.policy).

Guess you like

Origin blog.csdn.net/weixin_41267342/article/details/111060081