The installation

Download the official MySQL repository

MySQL 8.0.17 is used here

wget https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
​
Copy the code

Install MySQL repository

yum -y install mysql80-community-release-el7-3.noarch.rpm
Copy the code

MySQL installation

This is the community version, which is the free version.

yum -y install mysql-community-server
Copy the code

Because there are more than 400 meters, it takes a little time and patience to wait.

Check the version

[root@iZbp1b5bosh5hqwp4xnk3lZ ~]$mysql --version mysql Ver 8.0.19 for Linux on x86_64 (mysql Community Server-gpl)Copy the code

configuration

You can use either of these commands to manipulate mysql

  • systemctl {start|stop|restart|status} mysqld
  • service mysqld {start|stop|restart|status}

Start the

systemctl start mysqld
Copy the code

Check the status

systemctl status mysqld
Copy the code

If active (running) is displayed, the system is successfully started

Low mysqld. Service - MySQL Server the Loaded: the Loaded (/ usr/lib/systemd/system/mysqld. Service; enabled; Vendor preset: Disabled) Active: Active (running) since 22020-02-18 12:38:43 CST; 16min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 14487 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 14564 (mysqld) Status: "Server is operational" CGroup: / system. Slice/mysqld. Service └ ─ 14564 / usr/sbin/mysqld February 18 12:38:35 iZbp1b5bosh5hqwp4xnk3lZ systemd [1] : Starting MySQL Server... 2月 18 12:38:43 iZbp1b5bosh5hqwp4xnk3lZ SystemD [1]: Started MySQL ServerCopy the code

Default password The default password is stored in the log file during MySql installation. You can find the default password in the /var/logo/mysqld.log file root@localhost

[root@iZbp1b5bosh5hqwp4xnk3lZ ~] grep "password" /var/log/mysqld.log 2019-02-18t04:38:38.941142z 5 [MY-010454] [Server] A temporary password is generated for root@localhost: C2ZF? p.*uju9Copy the code

The login

You can omit -h when logging in to the local MySQL server

Mysql -u root -h localhost -p mysql -u root -h localhost -pCopy the code

If you operate the database without changing the default password, the following message is displayed, prompting you to change the password.

mysql> status
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Copy the code

Changing the Default Password

Mysql -> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';Copy the code

If your password is too simple, you will get the following prompt

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
Copy the code

The password must be 8 characters and must contain both numbers, upper case letters and special characters. The following is a successful example:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'A@123456'; Query OK, 0 rows affected (0.01sec)Copy the code

To reset your password

If you forget your password, you need to reset it

First stop the MySQL

sudo systemctl stop mysql
Copy the code

Start the MySQL

In this way, you do not need to enter a password when you log in after startup

sudo mysqld_safe --skip-grant-tables &
Copy the code

Log in and change your password

Mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'A@123456'; ALTER USER 'root'@'localhost' IDENTIFIED BY 'A@123456'; Grant -tables mysql> FLUSH PRIVILEGES;Copy the code

exit

mysql> exit;
Copy the code

Example Modify password security Settings

View MySQL global security variables

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      |
+--------------------------------------+--------+
Copy the code

Modify MySQL global variables

Mysql > set global validate_password.length=5; Query OK, 0 rows affected (0.00 SEC)Copy the code

The default encoding

The new version of MySQL has changed the default encoding from latin1 to UTF-8 MB4, so we don’t need to change that. Utf-8 MB4 supports emoji emoji compared to UTF-8.

Open port

MySQL listens on port 3306 by default, which needs to be enabled on the firewall.

[root@centos7 ~] firewall-cmd --zone=public --add-port=3306/ TCP --permanent success [root@centos7 ~] firewall-cmd reload success # Check whether port 3306 is opened successfully [root@centos7 ~] firewall-cmd --query-port=3306/ TCPCopy the code

The official document: dev.mysql.com/doc/refman/…