Centos7下MySQL 8.0安装与卸载

1、下载

https://dev.mysql.com/downloads/mysql/
Centos7下MySQL 8.0安装与卸载_第1张图片

2、安装

2.1 解压缩
[root@node1 app]# ll
总用量 817720
drwxr-xr-x. 8 10143 10143       273 6月   9 09:58 jdk1.8.0_301
-rw-r--r--  1 root  root  837345280 11月 11 06:25 mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar
[root@node1 app]# tar -xvf mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.27-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm
mysql-community-common-8.0.27-1.el7.x86_64.rpm
mysql-community-devel-8.0.27-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.27-1.el7.x86_64.rpm
mysql-community-libs-8.0.27-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm
mysql-community-server-8.0.27-1.el7.x86_64.rpm
mysql-community-test-8.0.27-1.el7.x86_64.rpm
[root@node1 app]# ll
总用量 1635440
drwxr-xr-x. 8 10143 10143       273 6月   9 09:58 jdk1.8.0_301
-rw-r--r--  1 root  root  837345280 11月 11 06:25 mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--  1  7155 31415  55178328 9月  29 03:33 mysql-community-client-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415   5932800 9月  29 03:34 mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415    641616 9月  29 03:34 mysql-community-common-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415   7760100 9月  29 03:34 mysql-community-devel-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415  23637616 9月  29 03:34 mysql-community-embedded-compat-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415   4935900 9月  29 03:34 mysql-community-libs-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415   1264256 9月  29 03:34 mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415 470252428 9月  29 03:36 mysql-community-server-8.0.27-1.el7.x86_64.rpm
-rw-r--r--  1  7155 31415 267724484 9月  29 03:38 mysql-community-test-8.0.27-1.el7.x86_64.rpm
[root@node1 app]# 

2.2 安装软件包
[root@node1 app]# yum install mysql-community-{libs,client,common,server}-*.rpm
已加载插件:fastestmirror
正在检查 mysql-community-libs-8.0.27-1.el7.x86_64.rpm: mysql-community-libs-8.0.27-1.el7.x86_64
mysql-community-libs-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm: mysql-community-libs-compat-8.0.27-1.el7.x86_64
mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-client-8.0.27-1.el7.x86_64.rpm: mysql-community-client-8.0.27-1.el7.x86_64
mysql-community-client-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm: mysql-community-client-plugins-8.0.27-1.el7.x86_64
mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-common-8.0.27-1.el7.x86_64.rpm: mysql-community-common-8.0.27-1.el7.x86_64
mysql-community-common-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-server-8.0.27-1.el7.x86_64.rpm: mysql-community-server-8.0.27-1.el7.x86_64
mysql-community-server-8.0.27-1.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-client-plugins.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-common.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-libs.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-server.x86_64.0.8.0.27-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================================================
 Package                                架构           版本                 源                                                           大小
==============================================================================================================================================
正在安装:
 mysql-community-client                 x86_64         8.0.27-1.el7         /mysql-community-client-8.0.27-1.el7.x86_64                 262 M
 mysql-community-client-plugins         x86_64         8.0.27-1.el7         /mysql-community-client-plugins-8.0.27-1.el7.x86_64          28 M
 mysql-community-common                 x86_64         8.0.27-1.el7         /mysql-community-common-8.0.27-1.el7.x86_64                 9.5 M
 mysql-community-libs                   x86_64         8.0.27-1.el7         /mysql-community-libs-8.0.27-1.el7.x86_64                    24 M
 mysql-community-libs-compat            x86_64         8.0.27-1.el7         /mysql-community-libs-compat-8.0.27-1.el7.x86_64            6.0 M
 mysql-community-server                 x86_64         8.0.27-1.el7         /mysql-community-server-8.0.27-1.el7.x86_64                 2.1 G

事务概要
==============================================================================================================================================
安装  6 软件包

总计:2.4 G
安装大小:2.4 G
Is this ok [y/d/N]: y^H^C
Exiting on user command
您的事务已保存,请执行:
 yum load-transaction /tmp/yum_save_tx.2021-11-11.09-16.Rfi5rn.yumtx 重新执行该事务
[root@node1 app]# yum install mysql-community-{libs,client,common,server}-*.rpm -y
已加载插件:fastestmirror
正在检查 mysql-community-libs-8.0.27-1.el7.x86_64.rpm: mysql-community-libs-8.0.27-1.el7.x86_64
mysql-community-libs-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm: mysql-community-libs-compat-8.0.27-1.el7.x86_64
mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-client-8.0.27-1.el7.x86_64.rpm: mysql-community-client-8.0.27-1.el7.x86_64
mysql-community-client-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm: mysql-community-client-plugins-8.0.27-1.el7.x86_64
mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-common-8.0.27-1.el7.x86_64.rpm: mysql-community-common-8.0.27-1.el7.x86_64
mysql-community-common-8.0.27-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-server-8.0.27-1.el7.x86_64.rpm: mysql-community-server-8.0.27-1.el7.x86_64
mysql-community-server-8.0.27-1.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-client-plugins.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-common.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-libs.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.27-1.el7 将被 安装
---> 软件包 mysql-community-server.x86_64.0.8.0.27-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================================================
 Package                                架构           版本                 源                                                           大小
==============================================================================================================================================
正在安装:
 mysql-community-client                 x86_64         8.0.27-1.el7         /mysql-community-client-8.0.27-1.el7.x86_64                 262 M
 mysql-community-client-plugins         x86_64         8.0.27-1.el7         /mysql-community-client-plugins-8.0.27-1.el7.x86_64          28 M
 mysql-community-common                 x86_64         8.0.27-1.el7         /mysql-community-common-8.0.27-1.el7.x86_64                 9.5 M
 mysql-community-libs                   x86_64         8.0.27-1.el7         /mysql-community-libs-8.0.27-1.el7.x86_64                    24 M
 mysql-community-libs-compat            x86_64         8.0.27-1.el7         /mysql-community-libs-compat-8.0.27-1.el7.x86_64            6.0 M
 mysql-community-server                 x86_64         8.0.27-1.el7         /mysql-community-server-8.0.27-1.el7.x86_64                 2.1 G

事务概要
==============================================================================================================================================
安装  6 软件包

总计:2.4 G
安装大小:2.4 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : mysql-community-client-plugins-8.0.27-1.el7.x86_64                                                                        1/6 
  正在安装    : mysql-community-common-8.0.27-1.el7.x86_64                                                                                2/6 
  正在安装    : mysql-community-libs-8.0.27-1.el7.x86_64                                                                                  3/6 
  正在安装    : mysql-community-client-8.0.27-1.el7.x86_64                                                                                4/6 
  正在安装    : mysql-community-server-8.0.27-1.el7.x86_64                                                                                5/6 
  正在安装    : mysql-community-libs-compat-8.0.27-1.el7.x86_64                                                                           6/6 
  验证中      : mysql-community-libs-8.0.27-1.el7.x86_64                                                                                  1/6 
  验证中      : mysql-community-common-8.0.27-1.el7.x86_64                                                                                2/6 
  验证中      : mysql-community-client-plugins-8.0.27-1.el7.x86_64                                                                        3/6 
  验证中      : mysql-community-server-8.0.27-1.el7.x86_64                                                                                4/6 
  验证中      : mysql-community-client-8.0.27-1.el7.x86_64                                                                                5/6 
  验证中      : mysql-community-libs-compat-8.0.27-1.el7.x86_64                                                                           6/6 

已安装:
  mysql-community-client.x86_64 0:8.0.27-1.el7                         mysql-community-client-plugins.x86_64 0:8.0.27-1.el7                   
  mysql-community-common.x86_64 0:8.0.27-1.el7                         mysql-community-libs.x86_64 0:8.0.27-1.el7                             
  mysql-community-libs-compat.x86_64 0:8.0.27-1.el7                    mysql-community-server.x86_64 0:8.0.27-1.el7                           

完毕!
[root@node1 app]# 

2.3 检查安装情况
[root@node1 app]# ps -ef | grep mysql
root      5111 25009  0 09:35 pts/2    00:00:00 grep --color=auto mysql
[root@node1 app]# mysqladmin --version
mysqladmin  Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
[root@node1 app]# cat /etc/group | grep mysql
mysql:x:27:
[root@node1 app]# 

3、初始化与基本配置

3.1 初始化操作

创建数据文件目录和mysql系统数据库 产生随机root密码

[root@node1 app]# mysqld --initialize
[root@node1 app]# 
3.2 目录权限授权
[root@node1 app]# chown -R mysql:mysql /var/lib/mysql/

注意,如果没有执行该步骤,下面启动服务会报错

[root@node1 app]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@node1 app]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 四 2021-11-11 09:40:07 EST; 19s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 10784 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 10758 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 10784 (code=exited, status=1/FAILURE)
   Status: "Server startup in progress"
    Error: 13 (权限不够)

11月 11 09:40:06 node1 systemd[1]: Starting MySQL Server...
11月 11 09:40:06 node1 systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
11月 11 09:40:07 node1 systemd[1]: Failed to start MySQL Server.
11月 11 09:40:07 node1 systemd[1]: Unit mysqld.service entered failed state.
11月 11 09:40:07 node1 systemd[1]: mysqld.service failed.
[root@node1 app]# 
3.3 启动服务
[root@node1 app]# systemctl start mysqld
[root@node1 app]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2021-11-11 09:46:54 EST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 18918 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 18942 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─18942 /usr/sbin/mysqld

11月 11 09:46:54 node1 systemd[1]: Starting MySQL Server...
11月 11 09:46:54 node1 systemd[1]: Started MySQL Server.
[root@node1 app]# 
[root@node1 app]# ps -ef | grep mysql
mysql    18942     1  0 09:46 ?        00:00:02 /usr/sbin/mysqld
root     24234 25009  0 09:51 pts/2    00:00:00 grep --color=auto mysql
[root@node1 app]# 
3.4 开机启动
[root@node1 app]# systemctl enable mysqld
[root@node1 app]# 

3.5 查看root密码
[root@node1 app]# cat /var/log/mysqld.log | grep password
2021-11-11T14:38:33.436049Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =dc_+Z3)LpSd
[root@node1 app]# 
3.6 安全设置
[root@node1 app]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:     【录入上面查询到随机密码dc_+Z3)LpSd】

The existing password for the user account root has expired. Please set a new password.

New password:                             【录入新密码,比如123456】

Re-enter new password:               【再次录入新密码】

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: no    【是否启用密码强度检查】
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no  【是否修改root密码,上面已经重新设置了】

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y   【录入y,删除匿名用户】
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y  【录入y,禁止root远程登录】
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  【录入y,删除临时库】
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y  【录入y,重新加载权限】
Success.

All done! 
[root@node1 app]# 
3.7 登录服务器
[root@node1 app]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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> 

4、卸载MySQL 8.0

4.1 查询已经安装的包
[root@node1 app]# rpm -qa|grep mysql
mysql-community-common-8.0.27-1.el7.x86_64
mysql-community-client-8.0.27-1.el7.x86_64
mysql-community-server-8.0.27-1.el7.x86_64
mysql-community-client-plugins-8.0.27-1.el7.x86_64
mysql-community-libs-8.0.27-1.el7.x86_64
mysql-community-libs-compat-8.0.27-1.el7.x86_64
[root@node1 app]# 
4.2 卸载软件包
[root@node1 ~]# yum -y remove mysql-*
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.8.0.27-1.el7 将被 删除
---> 软件包 mysql-community-client-plugins.x86_64.0.8.0.27-1.el7 将被 删除
---> 软件包 mysql-community-common.x86_64.0.8.0.27-1.el7 将被 删除
---> 软件包 mysql-community-libs.x86_64.0.8.0.27-1.el7 将被 删除
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.27-1.el7 将被 删除
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
---> 软件包 mysql-community-server.x86_64.0.8.0.27-1.el7 将被 删除
--> 正在检查事务
---> 软件包 postfix.x86_64.2.2.10.1-9.el7 将被 删除
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================================================
 Package                               架构          版本                   源                                                           大小
==============================================================================================================================================
正在删除:
 mysql-community-client                x86_64        8.0.27-1.el7           @/mysql-community-client-8.0.27-1.el7.x86_64                262 M
 mysql-community-client-plugins        x86_64        8.0.27-1.el7           @/mysql-community-client-plugins-8.0.27-1.el7.x86_64         28 M
 mysql-community-common                x86_64        8.0.27-1.el7           @/mysql-community-common-8.0.27-1.el7.x86_64                9.5 M
 mysql-community-libs                  x86_64        8.0.27-1.el7           @/mysql-community-libs-8.0.27-1.el7.x86_64                   24 M
 mysql-community-libs-compat           x86_64        8.0.27-1.el7           @/mysql-community-libs-compat-8.0.27-1.el7.x86_64           6.0 M
 mysql-community-server                x86_64        8.0.27-1.el7           @/mysql-community-server-8.0.27-1.el7.x86_64                2.1 G
为依赖而移除:
 postfix                               x86_64        2:2.10.1-9.el7         @anaconda                                                    12 M

事务概要
==============================================================================================================================================
移除  6 软件包 (+1 依赖软件包)

安装大小:2.4 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : mysql-community-server-8.0.27-1.el7.x86_64                                                                                1/7 
  正在删除    : mysql-community-client-8.0.27-1.el7.x86_64                                                                                2/7 
  正在删除    : 2:postfix-2.10.1-9.el7.x86_64                                                                                             3/7 
  正在删除    : mysql-community-libs-compat-8.0.27-1.el7.x86_64                                                                           4/7 
  正在删除    : mysql-community-libs-8.0.27-1.el7.x86_64                                                                                  5/7 
  正在删除    : mysql-community-common-8.0.27-1.el7.x86_64                                                                                6/7 
  正在删除    : mysql-community-client-plugins-8.0.27-1.el7.x86_64                                                                        7/7 
  验证中      : mysql-community-libs-8.0.27-1.el7.x86_64                                                                                  1/7 
  验证中      : 2:postfix-2.10.1-9.el7.x86_64                                                                                             2/7 
  验证中      : mysql-community-common-8.0.27-1.el7.x86_64                                                                                3/7 
  验证中      : mysql-community-client-plugins-8.0.27-1.el7.x86_64                                                                        4/7 
  验证中      : mysql-community-server-8.0.27-1.el7.x86_64                                                                                5/7 
  验证中      : mysql-community-client-8.0.27-1.el7.x86_64                                                                                6/7 
  验证中      : mysql-community-libs-compat-8.0.27-1.el7.x86_64                                                                           7/7 

删除:
  mysql-community-client.x86_64 0:8.0.27-1.el7                         mysql-community-client-plugins.x86_64 0:8.0.27-1.el7                   
  mysql-community-common.x86_64 0:8.0.27-1.el7                         mysql-community-libs.x86_64 0:8.0.27-1.el7                             
  mysql-community-libs-compat.x86_64 0:8.0.27-1.el7                    mysql-community-server.x86_64 0:8.0.27-1.el7                           

作为依赖被删除:
  postfix.x86_64 2:2.10.1-9.el7                                                                                                               

完毕!
[root@node1 ~]# 
[root@node1 ~]# rpm -qa|grep mysql
[root@node1 ~]# 

你可能感兴趣的:(数据库,centos,数据库,mysql,8.0)