彻底卸载Yum安装的MySQL数据库

  • 在我第二章MySQL数据库基于Centos7.3-部署过程中,因为以前安装过其它的版本所以没有卸载干净影响后期安装

一、MySQL数据库的官方网址:

  • https://www.oracle.com/
  • http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html
  •      
     //不同版本的安装文档和下载可以在这里找

折腾了大半天,看了想,想了看,总算是弄清楚yum安装的过程了,之前写过二进制包安装的,这里用yum安装,环境都是一样的,Centos7.2+MySQL5.7.18.

在linux上安装MySQL数据库,并简单设置用户密码,登录MySQL,linuxmysql

在新装的Centos系统上安装MySQL数据库。

<p><a
href=”;

>>提君博客原创    <<

第一步,检查是否已安装MySQL,如果已安装就卸载掉。

[[email protected] ~]# rpm -e mysql
error: package mysql is not installed

一步搞定,不需要事先执行检查命令了,直接执行卸载命令,有就删,没有也就不用管了。

第二步,执行安装

[[email protected] ~]# yum -y install mysql mysql-server mysql-devel
...
...
...
Complete!

出现complete表示安装成功。

>>提君博客原创    <<

第三步,开启服务

[[email protected] ~]# service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h ltt5.bg.cn password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

第四步,设置开机启动

[[email protected] ~]# chkconfig mysqld on
[[email protected] ~]# chkconfig --list  mysqld 
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

第五步,初始设置登录用户和密码

[[email protected] ~]# mysqladmin -u root password 'root'

第六步,登录MySQL数据库

[[email protected] ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.73 Source distribution

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

输入root密码,敲enter登录

第七步,查看帮助

mysql> help;

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

第八步,查看系统原装的数据库

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

第九步,创建数据库

<p><a
href=”;

mysql> create database hive
    -> ;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hive               |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)

第十步,退出

mysql> quit
Bye

至此,MySQL数据的安装和简单设置就介绍完毕。

>>提君博客原创    <<

<p><a
href=”;

在新装的Centos系统上安装MySQL数据库。 pa
href=”…

一、卸载Centos7自带的Maridb数据库

卸载maridb:
[root@host-131 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@host-131 ~]# yum -y remove mari*
[root@host-131 ~]# rm -rf /var/lib/mysql/*
[root@host-131 ~]# rpm -qa | grep mariadb
[root@host-131 ~]#

二、MySQL的安装方法:

以下是MySQL常见的三种安装方式:

  • 二进制  rpm   Yum Repository   
    mysql57-community-release-el7-9.noarch.rpm
  • 二进制  预编译  Generic                       
    mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
  • 源码包安             Source Code              
     
    mysql-5.7.19.tar.gz

每一步都参考了不少文章,后面会一一列举出来,因为本机已经安装过了,索性按照步骤一步一步卸载完成之后再重新安装。

二、彻底卸载MySQL数据库:

基于MySQL数据库基于Centos7.3-部署后,卸载mysql数据库:
[root@host-131 ~]# yum remove mysql-community-serve

使用remove发现还有部分残余文件:
这就是默认的卸载,其实还有很多 MySQL 依赖的软件包都并没有移除,
我们可以使用 rpm 命令的方式查看有哪些相关的软件名

[root@host-131 ~]# rpm -qa |grep mysql
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-server-5.7.22-1.el7.x86_64
mysql80-community-release-el7-1.noarch
mysql-community-client-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
[root@host-131 ~]# yum remove mysql-*    //挨个卸载

卸载并不会自动删除配置文件等,所以我们还需要手动来删除
[root@host-131 ~]# find / -name mysql
/etc/logrotate.d/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/share/mysql
[root@host-131 ~]# 
[root@host-131 ~]# rm -rf /var/lib/mysql     //将上边的文件全部删除

通过这个方法可以完全卸载MySQL

 

 

三、Yum的方法安装MySQL:

  • yum安装mysql 5.7
    的官方安装方法地址

1、下载安装包

  • *此地址为Mysql 8.0 的安装源其中包含MySQL
    5.7的源,可以在后边步骤修改开放的仓库:
     *

2、 设置安装初始环境

暂时先把防火墙关闭保证实验顺利:
[root@host-131 ~]# systemctl stop firewalld 
[root@host-131 ~]# systemctl disable firewalld.service
临时关闭SELlinux:
[root@host-131 ~]# setenforce 0
永久关闭SELinux:
[root@host-131 ~]# sed -ri '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
查看SELinux状态:
[root@host-131 ~]# getenforce
Disabled

 3、卸载系统自带的数据库(Centos7自带的是maridb)

本文通过一系列相对山寨的方式来实现,对于像本人一样接触linux时间不长的用户,相对也比较容易理解和接受,比如直接在Windows下面下载文件拖动到linux系统中而不是wget命令下载,直接通过winscp编辑器的编辑功能,而不是vim命令编辑.

可参考:【MySQL解惑笔记】Centos7下卸载彻底MySQL数据库

卸载maridb:
[root@host-131 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@host-131 ~]# yum -y remove mari*
[root@host-131 ~]# rm -rf /var/lib/mysql/*
[root@host-131 ~]# rpm -qa | grep mariadb
[root@host-131 ~]# 

4、修改仓库

[root@host-131 src]# yum rpolist all |grep mysql      //查看所有仓库,并能够看到开启和禁用的仓库
[root@host-131 src]# yum repolist enabled | grep "mysql.*-community.*"  //查看所有开启的仓库,发现现在开启的是MySQL 8.0的,我们需要开启MySQL5.7的仓库
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql80-community/x86_64          MySQL 8.0 Community Server                  17     //k

 开启和关闭不同仓库,官方提供了三种修改方法:

方法一:
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community

方法二:
shell> sudo dnf config-manager --disable mysql57-community
shell> sudo dnf config-manager --enable mysql56-community

方法三:
我们直接修改Yum源文件:
[root@host-131 ~]# cd /etc/yum.repos.d 
[root@host-131 yum.repos.d]# vim mysql-community.repo 
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1                        //修改为1表示开启
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0                        //修改为0表示关闭
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@host-131 yum.repos.d]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267    //可以看到5.7存储仓库已经开启

注意:我们应该在任何时候只启用一个发布系列的子存储库。当启用多个发布系列的子存储库时,Yum将使用最新的系列。
通过运行以下命令并检查其输出(对于Fedora,用dnf替换yum),验证是否启用了正确的子库并禁用了它:
[root@host-131 yum.repos.d]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267

 5、安装MySQL数据库

[root@host-131 yum.repos.d]# yum -y install mysql-community-server
[root@host-131 ~]# systemctl start mysqld   
[root@host-131 ~]# systemctl enable mysqld   设置开机自启动
[root@host-131 ~]# systemctl status mysqld  查看mysql启动状态

[root@host-131 ~]# ls /var/lib/mysql    (安装后可以看到初始化的数据库)
auto.cnf    client-cert.pem  ibdata1      ibtmp1      mysql.sock.lock     public_key.pem   sys
ca-key.pem  client-key.pem   ib_logfile0  mysql   performance_schema  server-cert.pem
ca.pem      ib_buffer_pool   ib_logfile1  mysql.sock  private_key.pem     server-key.pem

6、首次登录数据库,并设置初始化密码

[root@host-131 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
发现是禁止访问的

在服务器的初始启动时,由于服务器的数据目录为空:服务器初始化。SSL证书和密钥文件是在数据目录中生成的。
安装并启用了validate_password。
一个超级用户帐户'root'@'localhost被创建。
超级用户的密码被设置并存储在错误日志文件中。要显示它,请使用以下命令:

MySQL5.5之前版本安装后可以直接登录
MySQL5.5自动生成的密码是空的
MySQL5.6是将密码放在root下的
MySQL5.7是将密码放在:
[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"
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 4
Server version: 5.7.22
修改密码:
方法一:
[root@host-131 ~]# mysqladmin -uroot -p"xt8S3rWXOL/C" password "Yanglt123."   //密码要满足复杂性要求
[root@host-131 ~]# mysql -uroot -p"Yanglt123."

方法二:

[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

 到此数据库安装成功:

源码安装可参考文章:*【Linux运维】LNMP环境配置*

  

卸载

  操作系统版本

欧博国际平台 1

   rpm -qa | grep -i mysql
   rpm -qa | grep -i mysql命令查看已经安装过的组件。

欧博国际平台 2

使用yum -y
remove命令卸载已经安装的MySQL组件,使用下面的命令,对于上面已经安装的分别卸载,

yum -y remove mysql-community-libs-5.7.18-1.el7.x86_64
yum -y remove mysql-community-common-5.7.18-1.el7.x86_64
yum -y remove mysql-community-client-5.7.18-1.el7.x86_64
yum -y remove mysql57-community-release-el7-10.noarch
yum -y remove mysql-community-server-5.7.18-1.el7.x86_64

多的图就不截了,截一个示例一下。

欧博国际平台 3

   再次使用rpm -qa | grep -i mysql查看已安装的组件,已经完全卸载了。

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注