CentOS 7.x 卸载删除MariaDB

1、卸载

[root@node1 ~]# rpm -qa|grep mariadb

mariadb-5.5.56-2.el7.x86_64

mariadb-libs-5.5.56-2.el7.x86_64

mariadb-server-5.5.56-2.el7.x86_64

[root@node1~]#

用yum进行卸载:

[root@node1 ~]# yum remove mariadb

...

Removed:

mariadb.x86_641:5.5.56-2.el7

Dependency Removed:

mariadb-server.x86_64 1:5.5.56-2.el7

Complete![root@node1~]#

卸载完毕之后发现还有lib没有移除掉,直接卸载:

[root@localhost mysql-5.7.28-linux-glibc2.12-x86_64]# rpm -qa |grep mariadb

mariadb-libs-5.5.64-1.el7.x86_64

[root@localhost mysql-5.7.28-linux-glibc2.12-x86_64]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64

2、删除遗留目录

[root@node1 ~]# ls /etc/my.cnf/etc/my.cnf

[root@node1~]# ll /var/lib/mysql/total28700

-rw-rw---- 1 mysql mysql 16384 May 5 10:31 aria_log.00000001

-rw-rw---- 1 mysql mysql 52 May 5 10:31aria_log_control-rw-rw---- 1 mysql mysql 18874368 May 5 10:31ibdata1-rw-rw---- 1 mysql mysql 5242880 May 5 10:31ib_logfile0-rw-rw---- 1 mysql mysql 5242880 Oct 6 2017ib_logfile1

drwx------ 2 mysql mysql 4096 Oct 6 2017mysql

drwx------ 2 mysql mysql 4096 Oct 6 2017performance_schema

[root@node1~]#

[root@node1~]# rm -rf /etc/my.cnf

[root@node1~]# rm -rf /var/lib/mysql/

3、重新安装

[root@node1 ~]# yum install -y mariadb mariadb-server

[root@node1~]# systemctl start mariadb

[root@node1~]# systemctl enable mariadb

[root@node1~]# mysql_secure_installation

安装MYSQL离线版本

1. 检测mysql是否有相关文件,有的话进行卸载:

[root@localhost mysql-5.7.28-linux-glibc2.12-x86_64]# rpm -qa |grep mysql

qt-mysql-4.8.7-3.el7_6.x86_64

[root@localhost mysql-5.7.28-linux-glibc2.12-x86_64]# rpm -e --nodeps qt-mysql-4.8.7-3.el7_6.x86_64

2.检查mysql组合用户是否存在:

# 检查mysql组和用户是否存在,如无则创建

[root@CDH-141 ~]# cat /etc/group |grep mysql

[root@CDH-141 ~]# cat /etc/passwd | grep mysql

如果存在mysql组,则不需要新增,那么不存在mysql组,就需要新增一个mysql组:

[root@localhost ~]# groupadd mysql

如果存在mysql用户,则不需要新增,那么不存在mysql用户,就需要新增一个mysql用户:

[root@localhost ~]# useradd -g mysql mysql

修改mysql用户的密码:

[root@localhost ~]# passwd mysql

更改用户 mysql 的密码 。

新的 密码:

无效的密码: 密码少于8个字符

重新输入新的 密码:

抱歉,密码不匹配。

新的 密码:

无效的密码: 密码包含用户名在某些地方

重新输入新的 密码:

抱歉,密码不匹配。

新的 密码:

无效的密码: 密码未通过字典检查- 过于简单化/系统化

重新输入新的 密码:

抱歉,密码不匹配。

passwd: 已经超出服务重试的最多次数

3. 下载离线包

4. 上传离线包

[root@localhost src]# pwd/usr/local/src

[root@localhost src]# rz

解压离线包

[root@localhost src]# tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

修改解压包的名称,并移动到/usr/local目录下去

[root@localhost src]# mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql57

5. 更改mysql57文件夹的所属组和所属用户为mysql.mysql:

# 更改所属的组和用户[root@CDH-141 local]# chown -R mysql.mysql mysql57/[root@CDH-141 local]# cd mysql57/[root@CDH-141mysql57]# mkdir data

[root@CDH-141 mysql57]# chown -R mysql.mysql data

[mysql]

# 设置mysql客户端默认字符集default-character-set=utf8

socket=/var/lib/mysql/mysql.sock

[mysqld]

skip-name-resolve

# 设置3306端口

port= 3306socket=/var/lib/mysql/mysql.sock

# 设置mysql的安装目录

basedir=/usr/local/lnmp/mysql

# 设置mysql数据库的数据的存放目录

datadir=/usr/local/lnmp/mysql/data

# 允许最大连接数

max_connections=200# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎default-storage-engine=INNODB

lower_case_table_name=1max_allowed_packet=16M

查看mysql服务启动时候读取配置文件列表

1.首先通过which mysqld查找到该mysqld路径,然后cd到该目录。

2.键入 mysqld --verbose --help |grep -A 1 'Default options'命令来查看mysql使用的配置文件默认路径

windows下查看mysql读取配置文件的目录

mysql--help |findstr my.cnf

linux下查看mysql读取配置文件的目录

mysql--help | grep 'mysql\.cnf'

7.进入mysql57文件夹安装mysql:

其实只需要命令:

bin/mysqld --initialize

但是也可以补充,未补充的配置读取/etc/my.cnf文件

[root@localhost mysql57]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql57/ --datadir=/usr/local/mysql57/data/

2020-02-20T14:27:21.844182Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).2020-02-20T14:27:23.526945Z 0 [Warning] InnoDB: New log files created, LSN=45790

2020-02-20T14:27:23.705978Z 0[Warning] InnoDB: Creating foreign key constraint system tables.2020-02-20T14:27:23.800981Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1c750f6b-53ed-11ea-bc05-000c29d18f42.2020-02-20T14:27:23.803068Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed'cannot be opened.2020-02-20T14:27:24.224645Z 0 [Warning] CA certificate ca.pem isself signed.2020-02-20T14:27:24.380345Z 1 [Note] A temporary password is generated for root@localhost: p&fI(feaA6-=

创建系统服务,系统自启动