centos7下mysql5.7.42的安装配置

环境准备:
机器配置:

mysql5.7.42单机安装
1、二进制安装:
2、编辑配置文件:
3、初始化数据库:
4、配置环境变量:
5、制作启动文件:
6、用初始密码进入mysql,修改初始密码:
7、一些问题及解决办法

环境准备:

操作系统:CentOS7.9
[root@dengbao ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
mysql版本:mysql 5.7.42

1、二进制安装:

查看系统之前是否安装过mariadb 或者 mysql

rpm -qa | grep mariadb
rpm -pa | grep mysql

如果有则卸载

rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps      #这是强制卸载,不考虑依赖关系

再次检查

rpm -qa | grep mariadb
rpm -pa | grep mysql

官方已发布新版本。
https://dev.mysql.com/downloads/mysql/
目前8.0最新版本为8.0.33。

https://dev.mysql.com/downloads/mysql/5.7.html
目前5.7最新版本为5.7.42。
如下选择

image.png

下载这个


image.png

建立安装目录并上传mysql-5.7.42-el7-x86_64.tar.gz到/data/mysql7/下并解压

[root@dengbao ~]# mkdir -p /data/mysql7
[root@dengbao ~]# ll /data/
总用量 0
drwxr-xr-x 2 root  root   6 7月   5 15:21 mysql7

[root@dengbao ~]# cd /data/mysql7/
[root@dengbao mysql7]# ll
总用量 728568
-rw-r--r-- 1 root root 746050963 7月   5 11:36 mysql-5.7.42-el7-x86_64.tar.gz

[root@dengbao mysql7]# tar -zxvf  mysql-5.7.42-el7-x86_64.tar.gz 
mysql-5.7.42-el7-x86_64/bin/myisam_ftdump
mysql-5.7.42-el7-x86_64/bin/myisamchk
mysql-5.7.42-el7-x86_64/bin/myisamlog
mysql-5.7.42-el7-x86_64/bin/myisampack
mysql-5.7.42-el7-x86_64/bin/mysql
mysql-5.7.42-el7-x86_64/bin/mysql_client_test_embedded
mysql-5.7.42-el7-x86_64/bin/mysql_config_editor
mysql-5.7.42-el7-x86_64/bin/mysql_embedded
mysql-5.7.42-el7-x86_64/bin/mysql_install_db
mysql-5.7.42-el7-x86_64/bin/mysql_plugin
... ...
mysql-5.7.42-el7-x86_64/lib/libmysqlclient.so
mysql-5.7.42-el7-x86_64/lib/libmysqlclient.so.20
mysql-5.7.42-el7-x86_64/lib/libmysqlclient.so.20.3.29
mysql-5.7.42-el7-x86_64/share/install_rewriter.sql
mysql-5.7.42-el7-x86_64/share/uninstall_rewriter.sql
mysql-5.7.42-el7-x86_64/support-files/magic
mysql-5.7.42-el7-x86_64/support-files/mysql.server

[root@dengbao mysql7]# ll
总用量 728568
drwxr-xr-x 9 root root       129 7月   5 15:24 mysql-5.7.42-el7-x86_64
-rw-r--r-- 1 root root 746050963 7月   5 11:36 mysql-5.7.42-el7-x86_64.tar.gz

[root@dengbao mysql7]# ll mysql-5.7.42-el7-x86_64
总用量 268
drwxr-xr-x  2 root root    4096 7月   5 15:24 bin
drwxr-xr-x  2 root root      73 7月   5 15:23 docs
drwxr-xr-x  3 root root    4096 7月   5 15:23 include
drwxr-xr-x  5 root root     230 7月   5 15:24 lib
-rw-r--r--  1 7161 31415 255738 3月  16 23:25 LICENSE
drwxr-xr-x  4 root root      30 7月   5 15:23 man
-rw-r--r--  1 7161 31415    566 3月  16 23:25 README
drwxr-xr-x 28 root root    4096 7月   5 15:24 share
drwxr-xr-x  2 root root      90 7月   5 15:24 support-files

[root@dengbao mysql7]# mv mysql-5.7.42-el7-x86_64    /usr/local/mysql7

[root@dengbao mysql7]# ll /usr/local/
总用量 0
drwxr-xr-x. 2 root  root    6 4月  11 2018 bin
drwxr-xr-x. 2 root  root    6 4月  11 2018 etc
drwxr-xr-x. 2 root  root    6 4月  11 2018 games
drwxr-xr-x. 2 root  root    6 4月  11 2018 include
drwxr-xr-x. 2 root  root    6 4月  11 2018 lib
drwxr-xr-x. 2 root  root    6 4月  11 2018 lib64
drwxr-xr-x. 2 root  root    6 4月  11 2018 libexec
drwxr-xr-x  9 root  root  129 7月   5 15:24 mysql7
drwxr-xr-x. 2 root  root    6 4月  11 2018 sbin
drwxr-xr-x. 5 root  root   49 6月   4 09:34 share
drwxr-xr-x. 2 root  root    6 4月  11 2018 src

安装epel源

[root@dengbao mysql7]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm  /root
[root@dengbao mysql7]# cd /root
[root@dengbao ~]#  yum install -y epel-release-latest-7.noarch.rpm
[root@dengbao ~]# yum makecache fast
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                                  | 6.1 kB  00:00:00     
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                  | 3.6 kB  00:00:00     
epel                                                                                                                                                                  | 4.7 kB  00:00:00     
extras                                                                                                                                                                | 2.9 kB  00:00:00     
updates                                                                                                                                                               | 2.9 kB  00:00:00     
(1/3): epel/x86_64/updateinfo                                                                                                                                         | 1.0 MB  00:00:00     
(2/3): epel/x86_64/primary_db                                                                                                                                         | 7.0 MB  00:00:00     
(3/3): updates/7/x86_64/primary_db                                                                                                                                    |  22 MB  00:01:11     
元数据缓存已建立
[root@dengbao ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                                                                      源名称                                                                                                     状态
base/7/x86_64                                                               CentOS-7 - Base - mirrors.aliyun.com                                                                       10,072
epel/x86_64                                                                 Extra Packages for Enterprise Linux 7 - x86_64                                                             13,753
extras/7/x86_64                                                             CentOS-7 - Extras - mirrors.aliyun.com                                                                        515
updates/7/x86_64                                                            CentOS-7 - Updates - mirrors.aliyun.com                                                                     5,053
repolist: 29,393

yum repolist

安装依赖

[root@dengbao ~]# # yum -y install perl  net-tools
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.24.20131004git.el7 将被 升级
---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 更新
---> 软件包 perl.x86_64.4.5.16.3-291.el7 将被 升级
---> 软件包 perl.x86_64.4.5.16.3-299.el7_9 将被 更新
--> 正在处理依赖关系 perl-libs = 4:5.16.3-299.el7_9,它被软件包 4:perl-5.16.3-299.el7_9.x86_64 需要
--> 正在检查事务
---> 软件包 perl-libs.x86_64.4.5.16.3-291.el7 将被 升级
---> 软件包 perl-libs.x86_64.4.5.16.3-299.el7_9 将被 更新
--> 解决依赖关系完成

依赖关系解决

============================================================================================================================================================================
 Package                               架构                               版本                                                    源                                   大小
============================================================================================================================================================================
正在更新:
 net-tools                             x86_64                             2.0-0.25.20131004git.el7                                base                                306 k
 perl                                  x86_64                             4:5.16.3-299.el7_9                                      updates                             8.0 M
为依赖而更新:
 perl-libs                             x86_64                             4:5.16.3-299.el7_9                                      updates                             690 k

事务概要
============================================================================================================================================================================
升级  2 软件包 (+1 依赖软件包)

总下载量:8.9 M
Downloading packages:
No Presto metadata available for base
No Presto metadata available for updates
(1/3): net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                                                                                 | 306 kB  00:00:01     
(2/3): perl-libs-5.16.3-299.el7_9.x86_64.rpm                                                                                                         | 690 kB  00:00:02     
(3/3): perl-5.16.3-299.el7_9.x86_64.rpm                                                                                                              | 8.0 MB  00:00:25     
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                        354 kB/s | 8.9 MB  00:00:25     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : 4:perl-libs-5.16.3-299.el7_9.x86_64                                                                                                                     1/6 
  正在更新    : 4:perl-5.16.3-299.el7_9.x86_64                                                                                                                          2/6 
  正在更新    : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                               3/6 
  清理        : 4:perl-libs-5.16.3-291.el7.x86_64                                                                                                                       4/6 
  清理        : 4:perl-5.16.3-291.el7.x86_64                                                                                                                            5/6 
  清理        : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                                                               6/6 
  验证中      : 4:perl-5.16.3-299.el7_9.x86_64                                                                                                                          1/6 
  验证中      : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                               2/6 
  验证中      : 4:perl-libs-5.16.3-299.el7_9.x86_64                                                                                                                     3/6 
  验证中      : net-tools-2.0-0.24.20131004git.el7.x86_64                                                                                                               4/6 
  验证中      : 4:perl-5.16.3-291.el7.x86_64                                                                                                                            5/6 
  验证中      : 4:perl-libs-5.16.3-291.el7.x86_64                                                                                                                       6/6 

更新完毕:
  net-tools.x86_64 0:2.0-0.25.20131004git.el7                                                 perl.x86_64 4:5.16.3-299.el7_9                                                

作为依赖被升级:
  perl-libs.x86_64 4:5.16.3-299.el7_9                                                                                                                                       

完毕!

创建用户和用户组

groupadd mysql
useradd -g mysql mysql

创建mysql的数据、日志等数据存储目录

[root@dengbao mysql7]# pwd
/data/mysql7

[root@dengbao mysql7]# mkdir {data,log,var}
[root@dengbao mysql7]# ll
总用量 728568
drwxr-xr-x 2 root root         6 7月   5 16:49 data
drwxr-xr-x 2 root root         6 7月   5 16:49 log
drwxr-xr-x 2 root root         6 7月   5 16:49 var

给文件夹及文件授权

[root@dengbao mysql7]# chown -R mysql:mysql  /data/mysql7/
[root@dengbao mysql7]# chown -R mysql:mysql  /usr/local/mysql7/
[root@dengbao mysql7]#  ll /data/mysql7
总用量 0
drwxr-xr-x 2 mysql mysql 6 7月   5 16:49 data
drwxr-xr-x 2 mysql mysql 6 7月   5 16:49 log
drwxr-xr-x 2 mysql mysql 6 7月   5 16:49 var
[root@dengbao mysql7]#  ll /usr/local/mysql7
总用量 268
drwxr-xr-x  2 mysql mysql   4096 7月   5 15:24 bin
drwxr-xr-x  2 mysql mysql     73 7月   5 15:23 docs
drwxr-xr-x  3 mysql mysql   4096 7月   5 15:23 include
drwxr-xr-x  5 mysql mysql    230 7月   5 15:24 lib
-rw-r--r--  1 mysql mysql 255738 3月  16 23:25 LICENSE
drwxr-xr-x  4 mysql mysql     30 7月   5 15:23 man
-rw-r--r--  1 mysql mysql    566 3月  16 23:25 README
drwxr-xr-x 28 mysql mysql   4096 7月   5 15:24 share
drwxr-xr-x  2 mysql mysql     90 7月   5 15:24 support-files

2、编辑配置文件:

注意默认可能有/etc/my.cnf存在,备份 cp /etc/my.cnf /etc/my.cnf_back

[root@dengbao mysql7]# ll /etc/my*
ls: 无法访问/etc/my*: 没有那个文件或目录

在设置mysql数据库新密码前先不要在配置文件中设置“skip-name-resolve” 否则会报“Host ‘127.0.0.1’ is not allowed to connect to this MySQL server”解决办法就是先暂时注释掉这一条,设置好密码后再删除注释符号。


# vim /usr/local/mysql7/my.cnf

配置文件内容如下
[mysql]
default-character-set=utf8mb4
socket=/data/mysql7/var/mysql.sock

[mysqld]
basedir=/usr/local/mysql7
datadir=/data/mysql7/data
port=3309
socket=/data/mysql7/var/mysql.sock
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
log-error=/data/mysql7/log/mysqld.log
pid-file=/data/mysql7/var/mysqld.pid

query_cache_type = 1
query_cache_size = 32M
query_cache_limit = 2M

tmp_table_size = 1024M
max_heap_table_size = 1024M
#skip-name-resolve
innodb_print_all_deadlocks = 1
innodb_sort_buffer_size = 16M
slow_query_log = 1  
slow-query-log-file=/data/mysql7/log/slow.log  
long_query_time = 10
log-queries-not-using-indexes = 1
open_files_limit = 65535
max_connections = 4000
wait_timeout = 28800 
max_connect_errors = 1000
table_open_cache = 512
key_buffer_size = 512M
max_allowed_packet = 200M 
sort_buffer_size = 8M
join_buffer_size = 8M
net_buffer_length = 8K
read_buffer_size = 2M 
read_rnd_buffer_size = 1M 
myisam_sort_buffer_size = 20M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1 
thread_cache_size = 64
log_bin=/data/mysql7/data/mysql-bin
relay_log=relay_bin
log_slave_updates=on
gtid_mode=ON   
enforce_gtid_consistency=ON
binlog_format=mixed
binlog_cache_size = 1M
server-id = 2
expire_logs_days = 30
sql_mode =  STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_purge_threads = 1                        #收据回收使用单独线程
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_buffer_pool_size = 10G                 #设置物理内存的80%
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0                   #不限制并发数
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 30                   #事务等待超时,放弃事务回滚的时间10秒

[client]
port= 3309
default-character-set=utf8mb4
socket=/data/mysql7/var/mysql.sock

3、初始化数据库:

数据库初始化
[root@dengbao mysql7]# cd /usr/local/mysql7/
[root@dengbao mysql7]# ll
总用量 272
drwxr-xr-x  2 mysql mysql   4096 7月   5 15:24 bin
drwxr-xr-x  2 mysql mysql     73 7月   5 15:23 docs
drwxr-xr-x  3 mysql mysql   4096 7月   5 15:23 include
drwxr-xr-x  5 mysql mysql    230 7月   5 15:24 lib
-rw-r--r--  1 mysql mysql 255738 3月  16 23:25 LICENSE
drwxr-xr-x  4 mysql mysql     30 7月   5 15:23 man
-rw-r--r--  1 root  root    2046 7月   5 17:29 my.cnf
-rw-r--r--  1 mysql mysql    566 3月  16 23:25 README
drwxr-xr-x 28 mysql mysql   4096 7月   5 15:24 share
drwxr-xr-x  2 mysql mysql     90 7月   5 15:24 support-files
[root@dengbao mysql7]# chown -R mysql:mysql  /usr/local/mysql7/
[root@dengbao mysql7]# ll
总用量 272
drwxr-xr-x  2 mysql mysql   4096 7月   5 15:24 bin
drwxr-xr-x  2 mysql mysql     73 7月   5 15:23 docs
drwxr-xr-x  3 mysql mysql   4096 7月   5 15:23 include
drwxr-xr-x  5 mysql mysql    230 7月   5 15:24 lib
-rw-r--r--  1 mysql mysql 255738 3月  16 23:25 LICENSE
drwxr-xr-x  4 mysql mysql     30 7月   5 15:23 man
-rw-r--r--  1 mysql mysql   2046 7月   5 17:29 my.cnf
-rw-r--r--  1 mysql mysql    566 3月  16 23:25 README
drwxr-xr-x 28 mysql mysql   4096 7月   5 15:24 share
drwxr-xr-x  2 mysql mysql     90 7月   5 15:24 support-files

[root@dengbao mysql7]# su mysql
[mysql@dengbao mysql7]$ pwd
/usr/local/mysql7

[mysql@dengbao mysql7]$ ./bin/mysqld --initialize --lower-case-table-names=1 --user=mysql --basedir=/usr/local/mysql7 --datadir=/data/mysql7/data
2023-07-05T09:50:57.443239Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2023-07-05T09:50:57.443456Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2023-07-05T09:50:57.443841Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-07-05T09:50:58.626169Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-07-05T09:50:58.818397Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-07-05T09:50:58.881569Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 71957038-1b19-11ee-8e35-000c29b0bd44.
2023-07-05T09:50:58.896994Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-07-05T09:50:59.479203Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-07-05T09:50:59.479219Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-07-05T09:50:59.480386Z 0 [Warning] CA certificate ca.pem is self signed.
2023-07-05T09:50:59.736452Z 1 [Note] A temporary password is generated for root@localhost: qS,iqvajq5oY

[mysql@dengbao mysql7]$ ll /data/mysql7/data/
总用量 110660
-rw-r----- 1 mysql mysql       56 7月   5 17:50 auto.cnf
-rw------- 1 mysql mysql     1676 7月   5 17:50 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 7月   5 17:50 ca.pem
-rw-r--r-- 1 mysql mysql     1112 7月   5 17:50 client-cert.pem
-rw------- 1 mysql mysql     1676 7月   5 17:50 client-key.pem
-rw-r----- 1 mysql mysql      436 7月   5 17:51 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 7月   5 17:51 ibdata1
-rw-r----- 1 mysql mysql 50331648 7月   5 17:51 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 7月   5 17:50 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 7月   5 17:51 mysql
drwxr-x--- 2 mysql mysql     8192 7月   5 17:51 performance_schema
-rw------- 1 mysql mysql     1680 7月   5 17:50 private_key.pem
-rw-r--r-- 1 mysql mysql      452 7月   5 17:50 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 7月   5 17:50 server-cert.pem
-rw------- 1 mysql mysql     1676 7月   5 17:50 server-key.pem
drwxr-x--- 2 mysql mysql     8192 7月   5 17:51 sys

# 执行完后生成mysql默认root用户的密码 root@localhost: qS,iqvajq5oY 之后登录需要用到这里记录下来。

4、配置环境变量:

vim /etc/profile
# MYSQL7_HOME
MYSQL7_HOME=/usr/local/mysql7
export PATH=$PATH:$MYSQL7_HOME/bin

#刷新使环境变量生效
source /etc/profile

5、制作启动文件:

vim /etc/systemd/system/mysql7d.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql7/bin/mysqld --defaults-file=/usr/local/mysql7/my.cnf
LimitNOFILE = 65536
LimitNPROC = 65536

保存退出
重新加载service文件
systemctl daemon-reload
设置开机启动
[root@anolis mysql7]# systemctl enable mysql7d
Created symlink /etc/systemd/system/multi-user.target.wants/mysql7d.service → /etc/systemd/system/mysql7d.service.
日常启停命令
[root@dengbao mysql7]# systemctl status mysql7d.service
● mysql7d.service - MySQL Server
   Loaded: loaded (/etc/systemd/system/mysql7d.service; disabled; vendor preset: disabled)
   Active: active (running) since 三 2023-07-05 18:11:37 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 17704 (mysqld)
   CGroup: /system.slice/mysql7d.service
           └─17704 /usr/local/mysql7/bin/mysqld --defaults-file=/usr/local/mysql7/my.cnf

7月 05 18:11:37 dengbao systemd[1]: Started MySQL Server.

systemctl status mysql7d.service

systemctl stop mysql7d.service

6、用初始密码进入mysql,修改初始密码:

[root@dengbao log]# mysql -u root -p -h 127.0.0.1 -P 3309
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42-log

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass123';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user where user='root';
+-----------+------+
| host      | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)

mysql> update user set host='%',plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user where user='root';
+------+------+
| host | user |
+------+------+
| %    | root |
+------+------+
1 row in set (0.00 sec)

7、设置mysql仅指定的IP段可以访问

mysql> use mysql;
mysql> select host,user from user where user='root';

+------+------+
| host | user |
+------+------+
| %    | root |
+------+------+
mysql> update user set host='192.168.100.%',plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,plugin from user where user='root';
+---------------+------+-----------------------+
| host          | user | plugin                |
+---------------+------+-----------------------+
| 192.168.100.% | root | mysql_native_password |
+---------------+------+-----------------------+
1 row in set (0.00 sec)

退出后测试

[root@dengbao log]# mysql -u root -p -h 127.0.0.1 -P 3309
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@dengbao log]# mysql -u root -p -h 192.168.100.195 -P 3309
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.42-log MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

你可能感兴趣的:(centos7下mysql5.7.42的安装配置)