Linux mysql installation|configuration|operation|uninstallation

1. Uninstall mysql

1.1 First check whether the system has MySQL installed

rpm -qa | grep -i mysql

output:

perl-DBD-MySQL-4.050-13.el9.x86_64
mysql-community-client-plugins-8.0.30-1.el9.x86_64
mysql-community-common-8.0.30-1.el9.x86_64
mysql-community-libs-8.0.30-1.el9.x86_64
mysql-community-client-8.0.30-1.el9.x86_64
mysql-community-icu-data-files-8.0.30-1.el9.x86_64
mysql-community-server-8.0.30-1.el9.x86_64

As you can see from the output, the MySQL Server and Client I installed are both 8.0.30, and I will uninstall and reinstall it now.

1.2 Close the MySQL service

View the running status of the MySQL service:

service mysql status

The output is

SUCCESS! MySQL running (1084471)

Or
service mysqlindicates that the mysql service is running. Shut down the service first.

Or view the process of the mysql service

 ps -ef|grep mysql

Output:
insert image description here
Obviously, the mysql service is enabled.

Close the mysql service:

service mysql stop

output:

Shutting down MySQL.. SUCCESS!

Indicates that the mysql service has been successfully shut down.

1.3 View the folder corresponding to MySQL

find / -name mysql

output:

/home/wangdong/.local/lib/python3.8/site-packages/sqlalchemy/dialects/mysql
/etc/logrotate.d/mysql
/etc/pcp/pmlogconf/mysql
/etc/pcp/dstat/mysql
/var/lib/pcp/config/pmlogconf/mysql
/var/lib/selinux/targeted/active/modules/100/mysql
/var/lib/selinux/targeted/tmp/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/perl5/vendor_perl/auto/DBD/mysql
/usr/lib64/perl5/vendor_perl/DBD/mysql
/usr/lib64/mysql
/usr/share/pcp/htop/meters/mysql
/usr/share/bash-completion/completions/mysql
/usr/share/grafana/public/app/plugins/datasource/mysql
/usr/share/grafana/public/lib/monaco/min/vs/basic-languages/mysql
/usr/local/mysql

Delete these mysql directories, but be careful not to delete the database package in the python environment. Long snacks. first above.

1.4 Uninstall and delete the group key service installed by MySQL

rpm -ev mysql-community-common-8.3.30-1.el9.x86_64
rpm -ev mysql-community-release-8.3.30.noarch
rpm -ev mysql-community-client-8.3.30-1.el9.x86_64
rpm -ev mysql-community-server-8.3.30-1.el9.x86_64
rpm -ev mysql-community-libs-8.3.30-1.el9.x86_64

When uninstalling the service, I encountered the problem that the three component services could not be uninstalled, and it was prompted that the dependency postfix-2:2.10.1-7.el9.x86_64 was missing:

error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el9.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el9.x86_64

The solution is to add --nodeps to rpm -ev:
--nodeps means not to check dependencies during installation,
such as:

rpm -ev --nodeps mysql-community-client-8.0.30-1.el9.x86_64

1.5 Delete all MySQL folders in the system

rm -rf /etc/selinux/targeted/active/modules/100/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /usr/share/mysql
...

1.6 Finally verify whether MySQL is deleted

rpm -qa | grep -i mysql

If it is empty, congratulations, you have successfully deleted.

2. MySQL installation and configuration

2.1 Download mysql8.0 installation package

cd to /usr/local/, create the mysql directory, and download the mysql8.0 installation package

cd /usr/local/

You can find your favorite version on the official website: https://dev.mysql.com/downloads/mysql/
The relevant version demonstrated in this article is:
Linux: CentOS9
mysql: mysql-8.0.20

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

download successful
mysql

2.2 Unzip the mysql8.0 installation package

tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz 

mysql

2.3 Rename the directory to mysql

Rename the directory to mysql

mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql

Create a data directory storage file in the /use/local/mysql directory

mkdir data

2.4 Create mysql user groups and users respectively

Create user groups, users and passwords respectively (if the prompt exists, it has been created before)

groupadd mysql
useradd -g mysql mysql

2.5 Why do I need to create corresponding users and user groups when installing Mysql under Linux?

When running MySQL using a separate account and user group, the user and user group permissions can be controlled. When the permissions of files in the system are not set to Mysql users and user groups, Mysql users cannot perform read, write and execute operations. And if MySQL is hacked, it can pass that the permission obtained at the beginning is the created account instead of the default root. We create a mysql group and a mysql user when compiling and installing, and change the datadir and installation directory owner to for mysql.
When MySQL starts, there is a single process mysqld, and the owner of the process is mysql, which ensures the independence of the mysql service. Even if the mysql service is hacked and the mysql user authority is obtained, the security of the entire system will not be affected.

2.6 Authorize the newly created user

chown -R mysql.mysql /usr/local/mysql/mysql-8.0
chmod 750 /usr/local/mysql/mysql-8.0/data -R

2.7 Configure environment variables

Configure the environment, edit the /etc/profile file, that is, add a line to the fileexport PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

vim /etc/profile
#--------------------------
#点击键盘上的i键,进入输入模式,在配置文件最后增加一行:
#--------------------------
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
#添加完成后,按Esc键退出输入模式,进入命令模式,输入:wq,保存并退出
#然后在输入cat /etc/profile  查看是否保存成功,效果如下:↓↓↓↓↓↓

Note : After configuring the environment variables, you need to execute the source /etc/profile command to make the configuration file take effect.

2.8 Edit (create) my.cnf file

vi /etc/my.cnf
[mysql]
default-character-set=utf8mb4
[client]
#port=3306
socket=/var/lib/mysql/mysql.sock

[mysqld]
#port=3306
#server-id=3306
user=mysql
general_log = 1
general_log_file= /var/log/mysql/mysql.log
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-bin=/usr/local/mysql/data/mysql-bin
innodb_data_home_dir=/usr/local/mysql/data
innodb_log_group_home_dir=/usr/local/mysql/data/
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
default_authentication_plugin=mysql_native_password
symbolic-links=0
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid

#
# include all files from the config directory

Note:

  • MySQL added this utf8mb4 encoding after 5.5.3, mb4 means most bytes 4, and is specially used to be compatible with four-byte unicode. utf8mb4 is a superset of utf8, no conversion is required except changing the encoding to utf8mb4. Of course, in order to save space, it is usually enough to use utf8.

2.9 Initialize the basic information and get the initial password

cd to the /usr/local/mysql/bin directory, initialize the basic information, and get the initial password of the database (executed in the /usr/local/mysql/bin directory)

cd bin
./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --initialize
#初始化完成后,复制最后的初始密码,保存下来后面需要
#WgzUagc*e6V5

Pay attention to possible errors:
(1) mysqld: File '/var/log/mysql/mysql.log' not found (OS errno 2 - No such file or directory)

The directory does not exist, the installation prompts to create a directory

mysql

(2) The designated data directory /usr/local/mysql/data/ is unusable. You can remove all files that the server added to it. Although the first
initialization failed, it is already in this directory /usr/local The data generated under /mysql/data/ needs to be deleted before running the initialization command.
mysql
The screenshot of the successful operation is as follows:
mysql

Note to save the initial password here , which will be used for login later mysql -uroot -p.

2.10 Copy the mysql.server file and execute it in the /usr/local/mysql directory

cp -a ./support-files/mysql.server /etc/init.d/mysql 
cp -a ./support-files/mysql.server /etc/init.d/mysqld

2.11 Authorization

chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld

2.12 Create /var/lib/mysql

Check if the /var/lib/mysql directory exists, otherwise create it

mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/ 

2.13 Start the database

Start the database, and the word SUCCESS indicates that the MySQL installation is complete

service mysql start 
#出现SUCCESS 说明启动成功,效果图如下:

mysql
ps:
If you find that the startup fails, you can first check the mysql.log in the data. If there is a prompt like 3306, the first thing that comes to mind should be that the port is occupied. Use lsof -i: port number to check which PID (process No.) occupies the port, then use kill PID (process number) to kill the process and re-executeservice mysql start

2.14 Prepare to log in

mysql -u root -p

(1) 报错:mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
  • Solution 1:
yum install libtinfo* -y

insert image description here

  • Solution 2:
cp /lib64/libncurses.so.6 /lib64/libncurses.so.5
或者 添加软连接
ln -s /lib64/libncurses.so.6 /lib64/libncurses.so.5

insert image description here
(2) Error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
to find the mysql.sock file, the command is as follows:

find -name mysql.sock
  • If the file does not exist, you can refer to this article https://blog.csdn.net/haifu_xu/article/details/25281599

  • The file exists, but it does not exist in the /var/lib/mysql directory. Just make a soft connection. Before that, make sure that the current user is the root user, and the command is whoami. For example, mysql.sock is in the /tmp directory, and it is soft-linked to the /var/lib/mysql/ directory.

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

restart mysql afterwards

service mysqld start

2.15 Login successfully and reset password

After logging in, if you enter any command to report an error You must reset your password using ALTER USER statement before executing this statement; At this time, you need to reset the initial password-free

set password='your password'

reset mysql password
If the password meets the Mysql requirements, it will be modified successfully. If the following error message appears:

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

In the case that the password must be changed to run the operation, the password can be changed to a complex password that meets the requirements first. Then execute the following two statements, and then set the password to simple.

set global validate_password.policy=0;
# 有的是 set global validate_password.policy=LOW;
set global validate_password.length=6;
flush privileges;

2.16 Remote connection

An error is reported for remote connection with tools (such as Navicat), because there is no user permission for remote connection or no open port number.

  • User permissions
    Solution 1: Change the 'mysql' database 'user' table 'host' item from 'localhost' to '%'.
use mysql;
select host from user where user='root'; 
update user set host = '%' where user ='root';
flush privileges;

The operation screenshot is as follows:
mysql

select user,host from mysql.user;

Solution 2: Direct Authorization

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

  • Open port number
    If it is a physical server:
    check whether port 3306 is open
firewall-cmd --query-port=3306/tcp

Add port 3306 if it is not open

firewall-cmd --zone=public --add-port=3306/tcp --permanent

Refresh the firewall after adding the port

firewall-cmd --reload

mysql

If it is a cloud server:
mysql

3. mysql operation

We have modified the password of the root user after the installation is complete. Next, we will configure the relevant users.

3.1 Create user

CREATE USER 'usernamexxx'@'hostxxx' IDENTIFIED BY 'passwordxxx';

illustrate:

  • hostxxx: Specify the host on which the user can log in. If it is a local user, localhost can be used. If you want the user to log in from any remote host, you can use the wildcard %
  • passwordxxx: The login password of the user, the password can be empty, if it is empty, the user can log in to the server without a password

Example:

CREATE USER 'jack'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'rose'@'192.168.38.110_' IDENDIFIED BY '123456';
CREATE USER 'rose'@'%' IDENTIFIED BY '123456';
CREATE USER 'rose'@'%' IDENTIFIED BY '';
CREATE USER 'rose'@'%';

Notice:

After a user is created, the user can only connect to the database server, but does not have the authority to operate the database server.

3.2 Authorization

GRANT privilegesxxx ON databasenamexxx.tablenamexxx TO 'usernamexxx'@'hostxxx'

illustrate:

  • privilegesxxx: the user's operation authority, such as SELECT, INSERT, UPDATE, etc., if you want to grant all the permissions, use ALL
  • databasenamexxx: database name
  • tablenamexxx: table name, if you want to grant the user the corresponding operation permission on all databases and tables, it can be expressed, such as .*

Example:

GRANT SELECT, INSERT ON DbXXX.user TO 'jack'@'%';
GRANT ALL ON *.* TO 'jack'@'%';
GRANT ALL ON DbXXX.* TO 'jack'@'%';

Notice:

  1. After authorization, the user needs to reconnect to MySQL to obtain the corresponding permissions.
  2. The user authorized by the above command cannot authorize other users. If you want the user to be authorized, use the following command:
GRANT privilegesxxx ON databasenamexxx.tablenamexxx TO 'usernamexxx'@'hostxxx' WITH GRANT OPTION;

3.3 Setting and changing user password

Set and change user password

SET PASSWORD FOR 'usernamexxx'@'hostxxx' = PASSWORD('newpasswordxxx');

For the currently logged in user use:SET PASSWORD = PASSWORD("newpasswordxxx");

Example:

SET PASSWORD FOR 'jack'@'%' = PASSWORD("123456");

3.4 Revoking user rights

REVOKE privilegexxx ON databasenamexxx.tablenamexxx FROM 'usernamexxx'@'hostxxx';

Example:

REVOKE SELECT ON *.* FROM 'jack'@'%';

Note:
If you authorize the user 'jack'@'%' like this (or similar): , you cannot undo the user's SELECT operation on the user table in the test database GRANT SELECT ON test.user TO 'jack'@'%'by using the command. REVOKE SELECT ON *.* FROM 'jack'@'%';On the contrary, if the authorization is used GRANT SELECT ON *.* TO 'jack'@'%';, REVOKE SELECT ON test.user FROM 'jack'@'%';the command cannot revoke the user's Select permission to the user table in the test database.

The specific information can be viewed with the command SHOW GRANTS FOR 'jack'@'%';.

3.5 Delete user

DROP USER 'usernamexxx'@'hostxxx';

3.6 Mysql common command summary

1.创建用户
	格式:CREATE USER 'username'@'host' IDENTIFIED BY 'password';
	例如:CREATE USER 'chun'@'%' IDENTIFIED BY 'chun';
	
	PS:username - 你将创建的用户名,
	host - 指定该用户在哪个主机上可以登陆,此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录,如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录;也可以指定某台机器可以远程登录;
	password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器。

2.给用户授权
  1. 查询访问权限
  	select user,host from mysql.user;
  2. 给用户授权
	命令:GRANT privileges ON databasename.tablename TO 'username'@'host'
	例如:GRANT privileges ON *.* TO 'chun'@'%';
	PS: privileges - 用户的操作权限,如SELECT , INSERT , UPDATE 等(详细列表见该文最后面).如果要授予所的权限则使用ALL.;databasename - 数据库名,tablename-表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*表示, 如*.*.*

3.设置与更改用户密码
	命令:SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
	例子: SET PASSWORD FOR 'chun'@'%' = PASSWORD("chun");

4.撤销用户权限
    命令: REVOKE privilege ON databasename.tablename FROM 'username'@'host';
	说明: privilege, databasename, tablename - 同授权部分.
	例子: REVOKE SELECT ON mq.* FROM 'chun'@'localhost';

	PS: 假如你在给用户'dog'@'localhost''授权的时候是这样的(或类似的):GRANT SELECT ON test.user TO 'dog'@'localhost', 则在使用REVOKE SELECT ON *.* FROM 'dog'@'localhost';命令并不能撤销该用户对test数据库中user表的SELECT 操作.相反,如果授权使用的是GRANT SELECT ON *.* TO 'dog'@'localhost';则REVOKE SELECT ON test.user FROM 'dog'@'localhost';命令也不能撤销该用户对test数据库中user表的Select 权限.

    具体信息可以用命令SHOW GRANTS FOR 'dog'@'localhost'; 查看.
 
5.删除用户
    命令: DROP USER 'username'@'host';
      
6.查看用户的授权
	mysql> show grants for dog@localhost;
	PS:GRANT USAGE:mysql usage权限就是空权限,默认create user的权限,只能连库,啥也不能干
7.数据库的创建和销毁
	创建:create database 数据库名;
	例如:create database mytest;
	mysql> show databases;
	+--------------------+
	| Database           |
	+--------------------+
	| information_schema |
	| CARDGAME           |
	| mysql              |
	| mytest             |
	| performance_schema |
	| test               |
	+--------------------+
	销毁:drop database 数据库名;
	例如:drop database mytest;
	mysql> flush privileges;
	把新的数据库授权给新用户
	#将test库的所有权限赋予mysql用户
	grant all privileges on test.* to "mysql"@"%";
	grant all privileges on test.* to "tcl"@"%";
8.创建数据库表和删除表
	创建表:
		use 数据库名;
		create table tb_dept( Id int primary key auto_increment, Name varchar(18),description varchar(100));	
		mysql> show tables;
		+-------------------+
		| Tables_in_mystest |
		+-------------------+
		| tb_dept           |
		+-------------------+
		1 row in set (0.00 sec)
	删除表:drop table 表名;
			例如:drop table tb_dept;
9.给表添加索引:
	1.添加PRIMARY KEY(主键索引) 
		mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 
	2.添加UNIQUE(唯一索引) 
		mysql>ALTER TABLE `table_name` ADD UNIQUE (`column`) 
	3.添加INDEX(普通索引) 
		mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column` ) 
	4.添加FULLTEXT(全文索引) 
		mysql>ALTER TABLE `table_name` ADD FULLTEXT ( `column`) 
	5.添加多列索引 
		mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )

10. mysql编码
	1. 查看mysql编码
	show variables like '%character%';
	2. 为什么输入中文会报错,输入英文就成功了?
	原因:因为数据表中的内容为latin1字符集,latin1字符集为8bit,这说明它是不能表示中文的,因此会有报错。
	修改库字符集:
	alter database joyrun character set utf8;
	修改表字符集:
	alter table tbl_run character set utf8;
	修改字段字符集:
	alter table tbl_run change name name varchar(20) character set utf8;

4. Analyze whether the percent sign % in the MySQL user contains localhost?

When operating MySQL, I found that sometimes only % accounts were created, and I could connect through localhost, but sometimes I couldn’t. I couldn’t find a satisfactory answer by searching online, so I simply tested it manually.

4.1 Two connection methods

[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -hlocalhost
Enter password: 
mysql> status
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        9
Current database:    
Current user:        test_user@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        Localhost via UNIX socket

From Current user, you can see that the user is xx@localhost, and the connection method is Localhost via UNIX socket
-h parameter is IP
. When the -h parameter is IP, it is actually using TCP connection. The example is as follows

[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
mysql> status
--------------
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        11
Current database:    
Current user:        [email protected]
SSL:            Cipher in use is DHE-RSA-AES256-SHA
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP
Server characterset:    utf8

From Current user, you can see that the user is [email protected], and the connection method is TCP/IP

4.2 Differences between different versions

The test method is to see if it can be connected. If you don’t want to watch the test process, you can pull it to the end to see the conclusion

  1. MySQL 8.0
  • create user
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.11    |
+-----------+
1 row in set (0.00 sec)

mysql> create user test_user@'%' identified by 'test_user';
Query OK, 0 rows affected (0.07 sec)
  • login using localhost
[root@mysql-test-72 ~]# /usr/local/mysql80/bin/mysql -utest_user -p -hlocalhost
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.11 MySQL Community Server - GPL
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql80/bin/mysql  Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

Connection id:        9
Current database:    
Current user:        test_user@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        8.0.11 MySQL Community Server - GPL
Protocol version:    10
Connection:        Localhost via UNIX socket
...
  • Login using IP
[root@mysql-test-72 ~]# /usr/local/mysql80/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11 MySQL Community Server - GPL
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql80/bin/mysql  Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

Connection id:        8
Current database:    
Current user:        [email protected]
SSL:            Cipher in use is DHE-RSA-AES128-GCM-SHA256
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        8.0.11 MySQL Community Server - GPL
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP

The result shows MySQL version 8.0, % including localhost

  1. MySQL 5.7
  • create user
db83-3306>>create user test_user@'%' identified by 'test_user';
Query OK, 0 rows affected (0.00 sec)
  • login using localhost
[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -hlocalhost
Enter password: 
========= 省略 ===========

mysql> status
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        9
Current database:    
Current user:        test_user@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        Localhost via UNIX socket
....
  • Login using IP
[mysql@mysql-test-83 ~]$ /usr/local/mysql57/bin/mysql -utest_user -p -h127.0.0.1
Enter password: 
========= 省略 ===========

mysql> status
--------------
/usr/local/mysql57/bin/mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:        11
Current database:    
Current user:        [email protected]
SSL:            Cipher in use is DHE-RSA-AES256-SHA
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        5.7.21-log MySQL Community Server (GPL)
Protocol version:    10
Connection:        127.0.0.1 via TCP/IP
Server characterset:    utf8
...

The result shows MySQL version 5.7, % including localhost

4.3 Conclusion

Whether the % in version user includes localhost

mysql version % whether to include localhost
MySQL8.0 include
MySQL5.7 include
MySQL5.6 does not include
MySQL5.1 does not include
MariaDB 10.3 does not include

The above is to analyze whether the percent sign % in the MySQL user contains localhost?

5. Related articles

Joint Index, Index Covering and Index Pushdown Explained

Reference:
https://www.jb51.net/article/258197.htm
https://blog.csdn.net/haifu_xu/article/details/25281599

Guess you like

Origin blog.csdn.net/craftsman2020/article/details/128259334