First, preparation

  • 1. Update package

    yum update   
    Copy the code
  • 2. Check whether mysql has been installed

    rpm -qa | grep -i mysql
    Copy the code
  • 3, delete mysql

    yum -y remove MySQL-*
    Copy the code
  • 4. Delete the configuration file

    rm -rf /etc/my.cnf
    Copy the code
  • 5. Delete the default password

    rm -rf /root/.mysql_sercret
    Copy the code

Second, the installationmysql

  • 1. Go to usr and create a directory

    cd /usr
    mkdir soft
    Copy the code
  • 2. Configure the mysql installation source

    sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    Copy the code
  • 3, Install mysql

    sudo yum --enablerepo=mysql80-community install mysql-community-server
    Copy the code
  • 4. Start mysql

    sudo service mysqld start
    Copy the code
  • 5. Check the status

    service mysqld status
    Copy the code
    [root@iZwz9et2qekjwu8mwmxgxhZ usr]# service mysqld status
    Redirecting to /bin/systemctl status mysqld.service
    low mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2021-07-01 16:23:53 CST; 8s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 1171 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 1252 (mysqld)
       Status: "Server is operational"
       CGroup: /system.slice/mysqld.service
               └ ─ 1252 /usr/sbin/mysqld
    
    Jul 01 16:23:44 iZwz9et2qekjwu8mwmxgxhZ systemd[1]: Starting MySQL Server...
    Jul 01 16:23:53 iZwz9et2qekjwu8mwmxgxhZ systemd[1]: Started MySQL Server.
    [root@iZwz9et2qekjwu8mwmxgxhZ usr]# 
    Copy the code

3. Change passwords and remote login configurations

  • 1. View the temporary password

    grep "A temporary password" /var/log/mysqld.log
    Copy the code

  • 2. Use a temporary password to log in

    mysql -uroot -p
    Copy the code
  • 3, change the database password (directly change such a simple password will error, because of the password policy, must include :[uppercase letters + data + symbol])

    # Simple password
    ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
    # Compliant password
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'Aa@123456';
    Copy the code
  • 4. View the password policy (the password must be changed before execution)

    SHOW VARIABLES LIKE 'validate_password.%';
    Copy the code
    mysql> SHOW VARIABLES LIKE 'validate_password.%';
    +--------------------------------------+--------+
    | Variable_name | Value |
    +--------------------------------------+--------+
    | validate_password.check_user_name | ON |
    | validate_password.dictionary_file | |
    | validate_password.length | 8 |
    | validate_password.mixed_case_count | 1 |
    | validate_password.number_count | 1 |
    | validate_password.policy | MEDIUM |
    | validate_password.special_char_count | 1 |
    +--------------------------------------+--------+
    7 Rows in set (0.01sec)
    Copy the code
    • Validate_password. length is the minimum password length. The default is 8, but we’ll change it to 6

      set global validate_password.length=6;
      Copy the code
    • The complexity of validate_password.policy validates the password, which we change to 0

      set global validate_password.policy=0;
      Copy the code
    • Validate_password. check_user_name User name check. The user name and password cannot be the same

      set global validate_password.check_user_name=off;
      Copy the code
  • 5, this time can be changed to a simple password (simple password is only suitable for play database password, not suitable for production projects)

  • 6. Configure remote login

    CREATE USER 'root'@'%' IDENTIFIED BY '123456';
    Copy the code
  • 7. Refresh the configuration

    FLUSH PRIVILEGES
    Copy the code
  • 8. Connect directly to NavICat remotely

  • 9. Assign permissions

    # mysql8 was like this before
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    This is what happens after # mysql8
    grant all privileges on *.* to root@'%' with grant option;
    Copy the code
  • 10, Add content, set mysql startup

    systemctl start mysqld
    systemctl enable mysqld
    systemctl daemon-reload
    Copy the code
  • Stop mysql

    systemctl stop mysqld
    # or 
    service mysqld stop
    Copy the code

Four, the use ofdockerThe installationmysql8

  • 1, download mysql

    docker pull mysql
    Copy the code
  • 2. Check the installed mysql version

    docker image inspect mysql:latest | grep -i version
    Copy the code
  • 3. Create the mysql configuration file directory and data directory on the host and authorize it

    mkdir -p /usr/mysql/conf /usr/mysql/data
    chmod -R 755 /usr/mysql/
    Copy the code
  • 4. Create a configuration file

    vim /usr/mysql/conf/my.cnf
    Copy the code
    [client]
    
    #socket = /usr/mysql/mysqld.sock
    
    default-character-set = utf8mb4
    
    [mysqld]
    #pid-file = /var/run/mysqld/mysqld.pid
    #socket = /var/run/mysqld/mysqld.sock
    #datadir = /var/lib/mysql
    
    #socket = /usr/mysql/mysqld.sock
    
    #pid-file = /usr/mysql/mysqld.pid
    
    datadir = /usr/mysql/data
    
    character_set_server = utf8mb4
    
    collation_server = utf8mb4_bin
    
    secure-file-priv= NULL
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    
    symbolic-links=0
    
    # Custom config should go here
    ! includedir /etc/mysql/conf.d/
    Copy the code
  • 5. Start the container (note that it is in one line)

    docker run --restart=unless-stopped -d --name mysql -v /usr/mysql/conf/my.cnf:/etc/mysql/my.cnf -v 
    /usr/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
    Copy the code
  • 6. View the started container

    docker ps -a
    Copy the code
  • 7. Access the container to empower remote connections

    # Enter container
    docker exec -it mysql /bin/bash
    # enter the mysql
    mysql -uroot -p
    # change permission
    grant all privileges on *.* to root@'%' with grant option;
    Don't forget to refresh
    FLUSH PRIVILEGES
    Copy the code
  • Create a database in the container and check whether the new database can be seen in the client connection

    create database docker_test;
    Copy the code