MySQL installation piece

I. Introduction to the environment

Operating system: CentOS 7 MySQL 5.7

MySQL > uninstall MySQL

1. Check the MySQL software

rpm -qa|grep mysql
Copy the code

2. 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

Install MySQL

1, install,

# download yum
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
# install yum
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
# Use this command to view all the sub-repositories in the MySQL Yum repository and see which of them are enabled or disabled
yum repolist all | grep mysql
# close mysql8 download source
yum-config-manager --disable mysql80-community
# open mysql5.7 download source
yum-config-manager --enable mysql57-community
# installation mysql5.7
yum install -y mysql-community-server
Copy the code

2. Configure MySQL

vim /etc/my.cnf
Copy the code

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

3. Start MySQL

systemctl start mysqld
Copy the code

4. 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

1) View the initial password

2) Change the initial password

#1. Log in to mysql[root@localhost ~]# mysql -uroot -p't)WMH; uUe9Jn'#After mysql5.7, there are requirements for password strength, which must be composed of letters, digits and symbols. If you want to set simple password such as' root ', you need to do the following Settings
#2. Set the minimum length of a password
mysql> set global validate_password_length=4;
#3. Set the password strength level
mysql> set global  validate_password_policy=0;
#4. Change the password
mysql> alter user 'root'@'localhost' identified by 'root';
Copy the code

The values of validate_password_policy are as follows:

Policy Tests Performe
0 or LOW Length
1 or MEDIUM numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters

The default password is 1, that is, MEDIUM. Therefore, the password must contain digits, lowercase letters, uppercase letters, and special characters.

MySQL remote connection authorization

1. Log in to MySQL

  • The login command
mysql -uroot -proot
Copy the code
  • Command description:
-u: specifies the database user name. -p: specifies the database password. Remember that there is no space between -u and the login passwordCopy the code

2, authorization,

  • Authorization command
Grant permission on database object to userCopy the code
  • The sample

Grant root full access to all database objects:

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Copy the code
  • Command description:
    • ALL PRIVILEGES: indicates that all permissions are granted. You can specify specific permissions here.
    • *. *: represents all tables in all libraries
    • 'root'@'%': myuser is the database user name. % indicates any IP address. You can specify an IP address.
    • IDENTIFIED BY 'mypassword': mypassword is the password of the database.

5. Disable the Linux firewall

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

Close SELinux

1, check the status of SELinux

/usr/sbin/sestatus -v ## If SELinux status is enabled, SELinux status is enabledCopy the code

Close the SELinux method

1) Temporary shutdown (no need to restart the machine) :

Setenforce 0 # set SELinux to permissive mode#Setenforce 1 Set SELinux to enforcing mode
Copy the code

2) To modify the configuration file, restart the machine:

Modify the /etc/selinux/config file

Change SELINUX=enforcing to SELINUX=disabled

Just reboot the machine.