• 【MySQL入门指北】MySQL 彻底删除


    MySQL 彻底删除



    在这里插入图片描述


    这是我之前安装的mysql5.7,跟着相应的操作就可以删除干净。

    一、查看 mysql 的状态

    在这里插入图片描述

    [root@mysql-master2 ~]# systemctl status mysqld
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since 四 2022-11-10 00:23:37 CST; 1 day 13h ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 4941 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 4920 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 4944 (mysqld)
        Tasks: 29
       CGroup: /system.slice/mysqld.service
               └─4944 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    1110 00:23:32 mysql-master2 systemd[1]: Starting MySQL Server...
    1110 00:23:37 mysql-master2 systemd[1]: Started MySQL Server.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    二、关闭 msyql 服务

    [root@mysql-master2 ~]# systemctl stop mysqld
    [root@mysql-master2 ~]# systemctl status mysqld
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: inactive (dead) since 五 2022-11-11 13:58:05 CST; 3s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 4941 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 4920 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 4944 (code=exited, status=0/SUCCESS)
    
    1110 00:23:32 mysql-master2 systemd[1]: Starting MySQL Server...
    1110 00:23:37 mysql-master2 systemd[1]: Started MySQL Server.
    1111 13:58:02 mysql-master2 systemd[1]: Stopping MySQL Server...
    1111 13:58:05 mysql-master2 systemd[1]: Stopped MySQL Server.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    在这里插入图片描述

    三、删除 mysql

    1.查询MySQL安装的组件服务

    
    [root@mysql-master2 ~]# rpm -qa | grep -i mysql
    mysql-community-client-5.7.40-1.el7.x86_64
    zabbix-web-mysql-scl-5.0.28-1.el7.noarch
    mysql-community-embedded-5.7.40-1.el7.x86_64
    mysql-community-embedded-devel-5.7.40-1.el7.x86_64
    zabbix-server-mysql-5.0.28-1.el7.x86_64
    mysql-community-server-5.7.40-1.el7.x86_64
    zabbix-proxy-mysql-5.0.28-1.el7.x86_64
    mysql-community-libs-5.7.40-1.el7.x86_64
    mysql-community-libs-compat-5.7.40-1.el7.x86_64
    rh-php72-php-mysqlnd-7.2.24-1.el7.x86_64
    mysql-community-devel-5.7.40-1.el7.x86_64
    mysql-community-test-5.7.40-1.el7.x86_64
    mysql-community-embedded-compat-5.7.40-1.el7.x86_64
    perl-DBD-MySQL-4.023-6.el7.x86_64
    mysql80-community-release-el7-7.noarch
    mysql-community-common-5.7.40-1.el7.x86_64
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    2.将查询到的MySQL安装的组件服务删除

    [root@mysql-slave2 ~]# yum remove -y mysql-community*
    已加载插件:fastestmirror
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 mysql-community-client.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-common.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-devel.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-embedded.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-embedded-compat.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-embedded-devel.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-libs.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-libs-compat.x86_64.0.5.7.40-1.el7 将被 删除
    --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 perl-DBD-MySQL-4.023-6.el7.x86_64 需要
    --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 zabbix-server-mysql-5.0.28-1.el7.x86_64 需要
    --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 zabbix-proxy-mysql-5.0.28-1.el7.x86_64 需要
    --> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 perl-DBD-MySQL-4.023-6.el7.x86_64 需要
    --> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 zabbix-server-mysql-5.0.28-1.el7.x86_64 需要
    --> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 zabbix-proxy-mysql-5.0.28-1.el7.x86_64 需要
    ---> 软件包 mysql-community-server.x86_64.0.5.7.40-1.el7 将被 删除
    ---> 软件包 mysql-community-test.x86_64.0.5.7.40-1.el7 将被 删除
    --> 正在检查事务
    ---> 软件包 perl-DBD-MySQL.x86_64.0.4.023-6.el7 将被 删除
    ---> 软件包 zabbix-proxy-mysql.x86_64.0.5.0.28-1.el7 将被 删除
    ---> 软件包 zabbix-server-mysql.x86_64.0.5.0.28-1.el7 将被 删除
    --> 解决依赖关系完成
    
    依赖关系解决
    
    ===================================================================================================================================================================================================================
     Package                                                          架构                                    版本                                           源                                                   大小
    ===================================================================================================================================================================================================================
    正在删除:
     mysql-community-client                                           x86_64                                  5.7.40-1.el7                                   @mysql57                                            108 M
     mysql-community-common                                           x86_64                                  5.7.40-1.el7                                   @mysql57                                            2.8 M
     mysql-community-devel                                            x86_64                                  5.7.40-1.el7                                   @mysql57-community                                   24 M
     mysql-community-embedded                                         x86_64                                  5.7.40-1.el7                                   @mysql57-community                                  201 M
     mysql-community-embedded-compat                                  x86_64                                  5.7.40-1.el7                                   @mysql57-community                                   88 M
     mysql-community-embedded-devel                                   x86_64                                  5.7.40-1.el7                                   @mysql57-community                                  906 M
     mysql-community-libs                                             x86_64                                  5.7.40-1.el7                                   @mysql57                                             10 M
     mysql-community-libs-compat                                      x86_64                                  5.7.40-1.el7                                   @mysql57                                            5.9 M
     mysql-community-server                                           x86_64                                  5.7.40-1.el7                                   @mysql57                                            774 M
     mysql-community-test                                             x86_64                                  5.7.40-1.el7                                   @mysql57-community                                  671 M
    为依赖而移除:
     perl-DBD-MySQL                                                   x86_64                                  4.023-6.el7                                    @base                                               323 k
     zabbix-proxy-mysql                                               x86_64                                  5.0.28-1.el7                                   @zabbix                                             4.6 M
     zabbix-server-mysql                                              x86_64                                  5.0.28-1.el7                                   @zabbix                                             7.1 M
    
    事务概要
    ===================================================================================================================================================================================================================
    移除  10 软件包 (+3 依赖软件包)
    
    安装大小:2.7 G
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      正在删除    : mysql-community-embedded-devel-5.7.40-1.el7.x86_64                                                                                                                                            1/13 
      正在删除    : mysql-community-devel-5.7.40-1.el7.x86_64                                                                                                                                                     2/13 
      正在删除    : mysql-community-embedded-5.7.40-1.el7.x86_64                                                                                                                                                  3/13 
      正在删除    : mysql-community-test-5.7.40-1.el7.x86_64                                                                                                                                                      4/13 
      正在删除    : mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                                    5/13 
      正在删除    : mysql-community-client-5.7.40-1.el7.x86_64                                                                                                                                                    6/13 
      正在删除    : zabbix-server-mysql-5.0.28-1.el7.x86_64                                                                                                                                                       7/13 
    警告:/etc/zabbix/zabbix_server.conf 已另存为 /etc/zabbix/zabbix_server.conf.rpmsave
      正在删除    : mysql-community-embedded-compat-5.7.40-1.el7.x86_64                                                                                                                                           8/13 
      正在删除    : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                                                                                                             9/13 
      正在删除    : zabbix-proxy-mysql-5.0.28-1.el7.x86_64                                                                                                                                                       10/13 
    警告:/etc/zabbix/zabbix_proxy.conf 已另存为 /etc/zabbix/zabbix_proxy.conf.rpmsave
      正在删除    : mysql-community-libs-compat-5.7.40-1.el7.x86_64                                                                                                                                              11/13 
      正在删除    : mysql-community-libs-5.7.40-1.el7.x86_64                                                                                                                                                     12/13 
      正在删除    : mysql-community-common-5.7.40-1.el7.x86_64                                                                                                                                                   13/13 
      验证中      : mysql-community-client-5.7.40-1.el7.x86_64                                                                                                                                                    1/13 
      验证中      : zabbix-proxy-mysql-5.0.28-1.el7.x86_64                                                                                                                                                        2/13 
      验证中      : mysql-community-devel-5.7.40-1.el7.x86_64                                                                                                                                                     3/13 
      验证中      : mysql-community-server-5.7.40-1.el7.x86_64                                                                                                                                                    4/13 
      验证中      : mysql-community-common-5.7.40-1.el7.x86_64                                                                                                                                                    5/13 
      验证中      : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                                                                                                             6/13 
      验证中      : mysql-community-embedded-compat-5.7.40-1.el7.x86_64                                                                                                                                           7/13 
      验证中      : zabbix-server-mysql-5.0.28-1.el7.x86_64                                                                                                                                                       8/13 
      验证中      : mysql-community-embedded-5.7.40-1.el7.x86_64                                                                                                                                                  9/13 
      验证中      : mysql-community-libs-5.7.40-1.el7.x86_64                                                                                                                                                     10/13 
      验证中      : mysql-community-libs-compat-5.7.40-1.el7.x86_64                                                                                                                                              11/13 
      验证中      : mysql-community-test-5.7.40-1.el7.x86_64                                                                                                                                                     12/13 
      验证中      : mysql-community-embedded-devel-5.7.40-1.el7.x86_64                                                                                                                                           13/13 
    
    删除:
      mysql-community-client.x86_64 0:5.7.40-1.el7            mysql-community-common.x86_64 0:5.7.40-1.el7           mysql-community-devel.x86_64 0:5.7.40-1.el7   mysql-community-embedded.x86_64 0:5.7.40-1.el7     
      mysql-community-embedded-compat.x86_64 0:5.7.40-1.el7   mysql-community-embedded-devel.x86_64 0:5.7.40-1.el7   mysql-community-libs.x86_64 0:5.7.40-1.el7    mysql-community-libs-compat.x86_64 0:5.7.40-1.el7  
      mysql-community-server.x86_64 0:5.7.40-1.el7            mysql-community-test.x86_64 0:5.7.40-1.el7            
    
    作为依赖被删除:
      perl-DBD-MySQL.x86_64 0:4.023-6.el7                               zabbix-proxy-mysql.x86_64 0:5.0.28-1.el7                               zabbix-server-mysql.x86_64 0:5.0.28-1.el7                              
    
    完毕!
    [root@mysql-slave2 ~]# rpm -qa | grep -i mysql
    zabbix-web-mysql-scl-5.0.28-1.el7.noarch
    rh-php72-php-mysqlnd-7.2.24-1.el7.x86_64
    mysql80-community-release-el7-7.noarch
    [root@mysql-slave2 ~]# yum remove -y mysql80-community-release-el7-7.noarch
    已加载插件:fastestmirror
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 mysql80-community-release.noarch.0.el7-7 将被 删除
    --> 解决依赖关系完成
    
    依赖关系解决
    
    ===================================================================================================================================================================================================================
     Package                                                  架构                                  版本                                 源                                                                       大小
    ===================================================================================================================================================================================================================
    正在删除:
     mysql80-community-release                                noarch                                el7-7                                @/mysql80-community-release-el7-7.noarch                                 10 k
    
    事务概要
    ===================================================================================================================================================================================================================
    移除  1 软件包
    
    安装大小:10 k
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      正在删除    : mysql80-community-release-el7-7.noarch                                                                                                                                                         1/1 
    警告:/etc/yum.repos.d/mysql-community.repo 已另存为 /etc/yum.repos.d/mysql-community.repo.rpmsave
      验证中      : mysql80-community-release-el7-7.noarch                                                                                                                                                         1/1 
    
    删除:
      mysql80-community-release.noarch 0:el7-7                                                                                                                                                                         
    
    完毕!
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132

    3.查找出mysql对应的目录

    [root@mysql-master2 ~]# find / -name mysql
    /etc/selinux/targeted/active/modules/100/mysql
    /var/lib/mysql
    /var/lib/mysql/mysql
    /usr/share/mysql
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    4.将查找出mysql对应的目录删除

    [root@mysql-master2 ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql /var/lib/mysql /var/lib/mysql/mysql /usr/share/mysql
    [root@mysql-slave2 ~]# find / -name mysql
    
    
    
    • 1
    • 2
    • 3
    • 4

    5.删除mysql的配置文件 my.cnf

    [root@mysql-slave2 ~]# rm -rf /etc/my.cnf
    
    • 1

    6.在开启mysql服务,如果失败了则说明删除成功

    [root@mysql-slave2 ~]# systemctl start mysql
    Failed to start mysql.service: Unit not found.
    
    • 1
    • 2

    7.更改MySQL密码

    [root@mysql-master2 ~]# grep password /var/log/mysqld.log 
    2022-11-08T06:13:24.764470Z 1 [Note] A temporary password is generated for root@localhost: jCCzW8jNPw>f
    
    
    //这里更改一下数据库的密码可以更直观的感受到数据库恢复数据的过程
    [root@mysql-master2 ~]# mysqladmin -uroot -p're%f<7H1bi7s' password 'guan123456'
    装完mysql启动服务,第一次使用需要重置密码,显示我输入的密码"guan123456"太简单,在个人练习过程中,不想把密码设置太复杂
    
    [root@mysql-master2 ~]# grep password /var/log/mysql.log
    
    2022-11-08T06:13:24.764470Z 1 [Note] A temporary password is generated for root@localhost: jCCzW8jNPw>f
    # mysqladmin -uroot -p"jCCzW8jNPw>f" password "guan123456"
    mysqladmin: [Warning] Using a password on the command line interface can be insecure.
    Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
    mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'
    
    解决方案:
    
    # mysql -uroot -p'jCCzW8jNPw>f'
    
    (1)修改validate_password_policy参数值为0(1为开启复杂策略)
    
    注意:此参数(policy)必须优先修改,因为policy策略不修改为0会影响下面的length参数。
    
    mysql> set global validate_password_policy=0;
    
    (2)修改validate_password_length参数值为1
    
    mysql> set global validate_password_length=1;
    
    退出重新修改密码
    
    mysql > exit;
    
    [root@mysql-server ~]# mysqladmin -uroot -p'jCCzW8jNPw>f' password'guan123456'
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

  • 相关阅读:
    k8s认证
    动态规划(记忆化搜索)
    【BotR】CLR堆栈遍历(Stackwalking in CLR)
    Shell脚本:Linux Shell脚本学习指南(第二部分Shell编程)一
    SpringBoot项目将Nacos作为配置中心与注册中心,微服务启动失败
    【C++】多态/虚函数/虚表指针,虚表
    Anaconda中配置PyTorch环境——win10系统(小白包会)
    226. 翻转二叉树
    【开源】EValidator Java简单校验工具二
    不看后悔!第一本全面详解Transformer的综合性书籍!284页pdf下载
  • 原文地址:https://blog.csdn.net/guanguan12319/article/details/127804412