根本卸载Yum安装的MySQL数据库

  • 在自己第二章MySQL数据库基于Centos7.3-陈设进程中,因为在此以前设置过任何的本子所以并未有卸载干净影响早先时期安装

一、MySQL数据库的合French Open址:

  • 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的设置方式:

威澳门尼斯人36366com,以下是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境况安排*

  

卸载

  操作系统版本

威澳门尼斯人36366com 1

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

威澳门尼斯人36366com 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

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

威澳门尼斯人36366com 3

   再度使用rpm -qa | grep -i mysql查看已设置的零件,已经完全卸载了。

Author

发表评论

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