CentOS 7.9下MySQL 5.7安装和配置手册

2021/9/26 2:12:01

本文主要是介绍CentOS 7.9下MySQL 5.7安装和配置手册,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1. 安装前的准备

1.1 安装环境

1.1.1 操作系统内核版本

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

1.1.2 操作系统发行版本

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

1.2 安装文件

1.2.1 安装文件下载

  • 官网地址:https://www.mysql.com/
  • 下载地址:https://www.mysql.com/downloads/
  • 下载地址(快捷):https://downloads.mysql.com/archives/community/

1.2.2 安装文件列表

  • mysql-community-common-5.7.34-1.el7.x86_64.rpm
  • mysql-community-libs-5.7.34-1.el7.x86_64.rpm
  • mysql-community-server-5.7.34-1.el7.x86_64.rpm
  • mysql-community-client-5.7.34-1.el7.x86_64.rpm
  • mysql-community-devel-5.7.34-1.el7.x86_64.rpm

2. 安装和配置

2.1 软件安装

2.1.1 安装前的检测

  • 检测软件是否已安装
[root@localhost ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
  • 查看运行进程
[root@localhost ~]# ps -ef | grep mysql
root       4478   4237  0 12:12 pts/2    00:00:00 grep mysql
  • 停止数据库服务(可选)
[root@localhost ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
  • 依次卸载软件文件
[root@localhost ~]# rpm -e mysql-libs-5.1.73-8.el6_8.x86_64 --nodeps 

参数选项:

rpm -e mysql 普通删除模式

rpm -e --nodeps 强力删除模式,如果使用上面命令删除时,提示有依赖的其他文件,则用该命令可以对其进行强力删除。

2.1.2 安装MySQL

MySQL软件库依次安装如下:

  • 切换至软件目录;
[root@localhost ~]# cd /home/Software/MySQL/
[root@localhost MySQL]# ls
mysql-community-client-5.7.34-1.el7.x86_64.rpm  
mysql-community-devel-5.7.34-1.el7.x86_64.rpm  
mysql-community-server-5.7.34-1.el7.x86_64.rpm
mysql-community-common-5.7.34-1.el7.x86_64.rpm  
mysql-community-libs-5.7.34-1.el7.x86_64.rpm
  • 由于CentOS 7.9内置组件“mariadb-libs-1:5.5.68-1.el7.x86_64”与“mysql-community-common-5.7.34-1.el7.x86_64.rpm”存在包冲突,所以安装前先卸载;
[root@localhost MySQL]# rpm -e mariadb-libs-1:5.5.68-1.el7.x86_64 --nodeps 
  • 安装“mysql-community-common-5.7.34-1.el7.x86_64.rpm”;
[root@localhost MySQL]# sudo yum install -y mysql-community-common-5.7.34-1.el7.x86_64.rpm 
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-common-5.7.34-1.el7.x86_64.rpm: mysql-community-common-5.7.34-1.el7.x86_64
Marking mysql-community-common-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-common.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

Dependencies Resolved

==================================================================================================================================================================
 Package                                 Arch                    Version                       Repository                                                    Size
==================================================================================================================================================================
Installing:
 mysql-community-common                  x86_64                  5.7.34-1.el7                  /mysql-community-common-5.7.34-1.el7.x86_64                  2.8 M

Transaction Summary
==================================================================================================================================================================
Install  1 Package

Total size: 2.8 M
Installed size: 2.8 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
icedtea-web-1.7.1-2.el7_6.x86_64 has missing requires of java-1.8.0-openjdk
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
  Installing : mysql-community-common-5.7.34-1.el7.x86_64                                                                                                     1/1 
  Verifying  : mysql-community-common-5.7.34-1.el7.x86_64                                                                                                     1/1 

Installed:
  mysql-community-common.x86_64 0:5.7.34-1.el7                                                                                                                    

Complete!
  • 安装“mysql-community-libs-5.7.34-1.el7.x86_64.rpm”;
[root@localhost MySQL]# sudo yum install -y mysql-community-libs-5.7.34-1.el7.x86_64.rpm 
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-libs-5.7.34-1.el7.x86_64.rpm: mysql-community-libs-5.7.34-1.el7.x86_64
Marking mysql-community-libs-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

Dependencies Resolved

==================================================================================================================================================================
 Package                                Arch                     Version                        Repository                                                   Size
==================================================================================================================================================================
Installing:
 mysql-community-libs                   x86_64                   5.7.34-1.el7                   /mysql-community-libs-5.7.34-1.el7.x86_64                   9.5 M

Transaction Summary
==================================================================================================================================================================
Install  1 Package

Total size: 9.5 M
Installed size: 9.5 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-libs-5.7.34-1.el7.x86_64                                                                                                       1/1 
  Verifying  : mysql-community-libs-5.7.34-1.el7.x86_64                                                                                                       1/1 

Installed:
  mysql-community-libs.x86_64 0:5.7.34-1.el7                                                                                                                      

Complete!
  • 安装“mysql-community-client-5.7.34-1.el7.x86_64.rpm”;
[root@localhost MySQL]# sudo yum install -y mysql-community-client-5.7.34-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-client-5.7.34-1.el7.x86_64.rpm: mysql-community-client-5.7.34-1.el7.x86_64
Marking mysql-community-client-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

Dependencies Resolved

==================================================================================================================================================================
 Package                                 Arch                    Version                       Repository                                                    Size
==================================================================================================================================================================
Installing:
 mysql-community-client                  x86_64                  5.7.34-1.el7                  /mysql-community-client-5.7.34-1.el7.x86_64                  102 M

Transaction Summary
==================================================================================================================================================================
Install  1 Package

Total size: 102 M
Installed size: 102 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-client-5.7.34-1.el7.x86_64                                                                                                     1/1 
  Verifying  : mysql-community-client-5.7.34-1.el7.x86_64                                                                                                     1/1 

Installed:
  mysql-community-client.x86_64 0:5.7.34-1.el7                                                                                                                    

Complete!
  • 安装“mysql-community-server-5.7.34-1.el7.x86_64.rpm”;
[root@localhost MySQL]# sudo yum install -y mysql-community-server-5.7.34-1.el7.x86_64.rpm 
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-server-5.7.34-1.el7.x86_64.rpm: mysql-community-server-5.7.34-1.el7.x86_64
Marking mysql-community-server-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

Dependencies Resolved

==================================================================================================================================================================
 Package                                 Arch                    Version                       Repository                                                    Size
==================================================================================================================================================================
Installing:
 mysql-community-server                  x86_64                  5.7.34-1.el7                  /mysql-community-server-5.7.34-1.el7.x86_64                  761 M

Transaction Summary
==================================================================================================================================================================
Install  1 Package

Total size: 761 M
Installed size: 761 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-server-5.7.34-1.el7.x86_64                                                                                                     1/1 
  Verifying  : mysql-community-server-5.7.34-1.el7.x86_64                                                                                                     1/1 

Installed:
  mysql-community-server.x86_64 0:5.7.34-1.el7                                                                                                                    

Complete!
  • 安装“mysql-community-devel-5.7.34-1.el7.x86_64.rpm”;
[root@localhost MySQL5.7]# sudo yum install -y mysql-community-devel-5.7.34-1.el7.x86_64.rpm 
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-devel-5.7.34-1.el7.x86_64.rpm: mysql-community-devel-5.7.34-1.el7.x86_64
Marking mysql-community-devel-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

Dependencies Resolved

==================================================================================================================================================================
 Package                                Arch                    Version                         Repository                                                   Size
==================================================================================================================================================================
Installing:
 mysql-community-devel                  x86_64                  5.7.34-1.el7                    /mysql-community-devel-5.7.34-1.el7.x86_64                   24 M

Transaction Summary
==================================================================================================================================================================
Install  1 Package

Total size: 24 M
Installed size: 24 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-devel-5.7.34-1.el7.x86_64                                                                                                      1/1 
  Verifying  : mysql-community-devel-5.7.34-1.el7.x86_64                                                                                                      1/1 

Installed:
  mysql-community-devel.x86_64 0:5.7.34-1.el7                                                                                                                     

Complete!

2.2 软件配置

2.2.1 查看运行状态

[root@localhost ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-09-11 05:17:30 PDT; 2min 54s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 64164 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 64137 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 64167 (mysqld)
    Tasks: 28
   CGroup: /system.slice/mysqld.service
           └─64167 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Sep 11 05:17:28 localhost.localdomain systemd[1]: Starting MySQL Server...
Sep 11 05:17:30 localhost.localdomain systemd[1]: Started MySQL Server.

2.2.2 查看默认密码

  • 启动数据库服务
[root@localhost ~]# systemctl start mysqld 
  • 查找默认密码
[root@localhost MySQL]# grep 'temporary password' /var/log/mysqld.log
2021-09-11T12:12:38.597863Z 1 [Note] A temporary password is generated for root@localhost: Ik8r-W0FefUo

(特别说明:由于安装时自动生成了默认密码,所以登录前需要事先查找默认密码。默认密码为“:,rkTG:o7+0-”。如果提示找不到“mysqld.log”文件,则先执行“systemctl status mysqld”确认MySQL是否正常运行,如果未正常运行,则执行“systemctl start mysqld”,数据库初始化后,会自动生成“mysqld.log”文件)

2.2.3 重设默认密码

  • 登录数据库(略)
  • 重设默认密码
mysql> set password for 'root'@'localhost'=password('Db0AdMiN1!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

(特别说明:新密码必须包含大小写字母、符号、数字)

  • 退出数据库(略)

2.2.4 修改默认编码

  • 修改默认编码
[root@localhost ~]# vim /etc/my.cnf

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
  • 重启数据库服务
[root@localhost ~]# systemctl start mysqld
  • 登录数据库(略)

  • 查看修改编码

mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

2.2.5 修改默认最大连接

  • 修改默认最大连接
[root@localhost ~]# vim /etc/my.cnf

[mysqld]
max_connections=200
  • 重启数据库服务
[root@localhost ~]# systemctl restart mysqld
  • 登录数据库(略)
  • 验证修改最大连接
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 rows in set (0.00 sec)

2.2.6 添加远程登录用户

  • 登录数据库(略)
  • 新增远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'luxus'@'%' IDENTIFIED BY 'Db0AdMiN1!' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

(特别说明:luxus为新用户名,Db0AdMiN1!为新密码)

  • 将数据库用户host字段“localhost”修改为“%”
mysql> use mysql;
Database changed

mysql> update user set host="%" where user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

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

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | luxus         |
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
4 rows in set (0.00 sec)

(特别说明:如果这些配置都做完了,还是无法远程访问数据库,这个时候可以检查一下Linux服务器的防火墙是否已关闭,如防火墙已开启,则关闭即可)

2.2.7 禁用系统防火墙

[root@localhost ~]# systemctl disable firewalld

2.2.8 设置自动启动

MySQL 5.7数据库安装成功后,默认已设置为自启动。

2.2.9 修改大小写敏感

lower_case_table_names=1(0:区分大小写;1:不区分大小写);

  • 修改大小写敏感
[root@localhost ~]# vim /etc/my.cnf
[mysqld] 
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock 
lower_case_table_names=1
  • 重启数据库服务
[root@localhost ~]# systemctl restart mysqld
  • 登录数据库(略)
  • 验证修改大小写敏感
mysql> show variables like '%case%';
+------------------------------------+-------+
| Variable_name                      | Value |
+------------------------------------+-------+
| lower_case_file_system             | OFF   |
| lower_case_table_names             | 1     |
| validate_password_mixed_case_count | 1     |
+------------------------------------+-------+
3 rows in set (0.00 sec)

2.2.10 修改账号密码

  • 登录数据库(略)
  • 修改账号密码
mysql> update user set authentication_string=password('Db0AdMiN1!13') where user='luxus' and host='%'; 
Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 

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

2.2.11 修改默认端口

  • 修改默认端口
[root@localhost ~]# vim /etc/my.cnf

[mysqld] 
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock 
port=3306
  • 重新数据库服务
[root@localhost ~]# systemctl restart mysqld

2.2.12 禁用DNS扫描

  • 修改禁用DNS扫描
[root@localhost ~]# vim /etc/my.cnf

[mysqld] 
skip-name-resolve
  • 重启数据库服务
[root@localhost ~]# systemctl restart mysqld

(特别说明:如果远程连接数据库较慢,可禁用MySQL数据库DNS自动扫描)

3. 启动和验证

3.1 软件启动

3.1.1 启动数据库服务

[root@localhost ~]# systemctl start mysqld

3.1.2 重启数据库服务

[root@localhost ~]# systemctl restart mysqld

3.2 软件验证

3.2.1 查看软件版本

[root@localhost MySQL5.7]# mysql -V
mysql  Ver 14.14 Distrib 5.7.34, for Linux (x86_64) using  EditLine wrapper

(特别说明:V是大写)

3.2.2 查看软件运行状态

[root@localhost ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-09-11 05:17:30 PDT; 2min 54s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 64164 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 64137 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 64167 (mysqld)
    Tasks: 28
   CGroup: /system.slice/mysqld.service
           └─64167 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Sep 11 05:17:28 localhost.localdomain systemd[1]: Starting MySQL Server...
Sep 11 05:17:30 localhost.localdomain systemd[1]: Started MySQL Server

3.2.3 登录/退出数据库

[root@localhost MySQL]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.31

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> exit;
Bye

3.2.4 远程连接数据库

4. 停止和卸载

4.1 软件停止

暂无。

4.2 软件卸载

  • 检测库文件是否存在
[root@localhost ~]# rpm -qa | grep jdk
jdk-11.0.12-11.0.12-ga.x86_64
  • 依次卸载软件文件
[root@localhost ~]# rpm -e jdk-11.0.12-11.0.12-ga.x86_64 --nodeps

参数选项:

rpm -e jdk 普通删除模式

rpm -e --nodeps 强力删除模式,如果使用上面命令删除时,提示有依赖的其他文件,则 用该命令可以对其进行强力删除。

5. 安装目录和核心文件

5.1 安装目录

[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

[root@localhost JDK]# find / -name mysql
find: ‘/run/user/1000/gvfs’: Permission denied
/etc/logrotate.d/mysql
/etc/selinux/targeted/active/modules/100/mysql
/etc/selinux/targeted/tmp/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/share/mysql
/usr/include/mysql
/usr/include/mysql/mysql

5.2 执行文件

[root@localhost ~]# which mysql
/usr/bin/mysql

5.3 配置文件

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

5.4 日志文件

[root@localhost ~]# vim /var/log/mysqld.log

2021-09-11T12:12:37.022281Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-11T12:12:37.414566Z 0 [Warning] InnoDB: New log files created, LSN=45790
...

6. 常见问题

6.1 安装community-common时,提示与mariadb-libs包冲突

问题原因:由于CentOS 7.9内置组件“mariadb-libs-1:5.5.68-1.el7.x86_64”与“mysql-community-common-5.7.34-1.el7.x86_64.rpm”存在包冲突,所以安装前先卸载。

解决方案:

[root@localhost MySQL]# rpm -e mariadb-libs-1:5.5.68-1.el7.x86_64 --nodeps 

6.2 正确添加远程用户后还是不能远程访问

问题原因:那可能是系统防火墙打开了,关闭即可。

解决方案:

[root@localhost ~]# systemctl disable firewalld

6.3 远程访问数据库连接很慢

问题原因:那可能远程连接自动扫描DNS,禁用即可。

解决方案:

[root@localhost ~]# vim /etc/my.cnf
[mysqld] 
skip-name-resolve

[root@localhost ~]# systemctl restart mysqld


这篇关于CentOS 7.9下MySQL 5.7安装和配置手册的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程