Environment introduction

Operating system: CentOS 7

MySQL: 5.7

Yum install

MySQL uninstall

  • Checking the MySQL software

    rpm -qa|grep mysql

  • Uninstall MySQL

    yum remove -y mysql mysql-libs mysql-common 
    
    rm -rf /var/lib/mysql 
    
    rm /etc/my.cnf
    Copy the code

    Check to see if there is any MySQL software available, and continue deleting if so

    After the software is uninstalled, you can delete the MySQL database: /var/lib/mysql

MySQL installation

The installation

# download to install source of a yum yum wget source https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm # RPM - the ivh # mysql80-community-release-el7-3.noarch. RPM # mysql80-community-release-el7-3.noarch. RPM # mysql80-community-release-el7-3.noarch. RPM And see which of these son repository has enable or disable the yum repolist all | grep mysql # close mysql8 download source yum - config - manager - disable mysql80 - community (if prompted Yum - config manager: command not found, # yum -y install yum-utils) # yum-config-manager --enable mysql57-community # mysql5.7 yum install -y mysql-community-serverCopy the code

Configure the MySQL

vim /etc/my.cnf

The modifications are as follows

[mysqld] # mysqld # mysqld # mysqld # mysqld # mysqld Case insensitive lower_case_table_names=1 # Default character set character-set-server= UTf8Copy the code

Start the MySQL

systemctl start mysqld

Example Set the password of user root

After installing mysql5.7, the default password is no longer empty and a default password is generated for the initial password. The password is output to the mysql log. The log file is located in /var/log/mysqld.log

Changing the Initial Password

[root@localhost ~]# mysql -uroot -p'password' #mysql5.7 The following Settings are required #2. Mysql > set global validate_password_length=4; Mysql > set global validate_password_policy=0; Mysql > alter user 'root'@'localhost' identified by 'root'Copy the code

MySQL remote connection authorization

Log on to the MySQL

  • The login command

    mysql -uroot -proot

  • The command that

    -u: specifies the database user name

    -p: specifies the database password. Remember that there is no space between -u and the login password

authorization

  • Authorization command

    Grant permission on database object to user

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

  • The command that

    • ALL PRIVILEGES: Indicates that ALL PRIVILEGES are granted. You can specify specific PRIVILEGES

    • . : represents all tables in all libraries

    • ‘root’@’%’ : myuser is the user name of the database. % indicates any IP address, which can be specified

    • IDENTIFIED BY ‘mypassword’ : Mypassword is the database password

  • Refresh the permissions

    FLUSH PRIVILEGES

Disable the Linux firewall

Systemctl stop firewalld (default) systemctl disable firewalld.serviceCopy the code

Docker installation

  • Pull the mirror

    Docker pull mysql: 5.7

  • Look at mirror

    docker images

  • Start the mysql

    sudo docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ - v/mydata/mysql/conf: / etc/mysql \ - e MYSQL_ROOT_PASSWORD = root \ - d mysql: 5.7Copy the code
  • Query started containers

    docker ps

  • Modify the configuration

    [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve # Docker restart mysqlCopy the code
  • Set to run mysql when Docker is started

    docker update mysql --restart=always