MySQ彻底删除与安装配置

Posted inmoonlight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQ彻底删除与安装配置相关的知识,希望对你有一定的参考价值。

彻底删除

1.查看 mysql 安装了哪些东西

rpm -qa |grep -i mysql

技术图片

 2.卸载

yum remove mysql-community-common-5.7.20-1.el7.x86_64
yum remove mysql-community-client-5.7.20-1.el7.x86_64
yum remove mysql57-community-release-el7-11.noarch
yum remove mysql-community-libs-5.7.20-1.el7.x86_64
yum removemysql-community-server-5.7.20-1.el7.x86_64
mariadb 也要删除
rpm -qa | grep mariadb

rpm -e --nodeps 包名称(比如:rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64)

3.查看是否卸载完成

技术图片

 4.查找 MySQL 相关目录

find / -name mysql

技术图片

5.删除相关目录

rm -rf 

技术图片

 6.删除  /etc/my.cnf 

rm -rf /etc/my.cnf

7.删除 /var/log/mysqld.log (如果不删除这个文件,会导致新安装的 MySQL 无法生成新密码,导致无法登陆)

rm -rf /var/log/mysqld.log

安装

1.增加官方的 yum 源(以5.6 为例)

创建并编辑 mysql-community.repo 文件
vi /etc/yum.repos.d/mysql-community.repo
将以下内容粘贴进去并保存
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

注意:gpgcheck是GPG加密校验,官方文档中值为1,但check会报错误,所以这里改为0跳过检查,对安装无影响。

2.安装 MySQL

sudo yum -y install mysql-community-server

效果如下:

Installed:
  mysql-community-server.x86_64 0:5.6.41-2.el7                                     

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.41-2.el7                                     
  mysql-community-common.x86_64 0:5.6.41-2.el7                                     
  mysql-community-libs.x86_64 0:5.6.41-2.el7                                       
  net-tools.x86_64 0:2.0-0.22.20131004git.el7                                      
  perl-DBI.x86_64 0:1.627-4.el7                                                    
  perl-Net-Daemon.noarch 0:0.48-5.el7                                              
  perl-PlRPC.noarch 0:0.2020-14.el7                                                

Complete!

3.启动 MySQL 并允许 MySQL 自启

sudo systemctl start mysqld
sudo systemctl enable mysqld

配置编码

1.进入 MySQL 查看编码

show variables like %character%;

结果如下:

mysql> show variables like %character%;
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

2.修改编码

sudo vi /etc/my.cnf
# 然后在 [mysqld] 下添加 character-set-server=utf8

sudo vi /etc/my.cnf.d/client.cnf
# 然后在 [client] 下添加 default-character-set=utf8

3.再次查看编码:

mysql> show variables like %character%;
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

 

以上是关于MySQ彻底删除与安装配置的主要内容,如果未能解决你的问题,请参考以下文章

彻底删除vscode及安装的插件和个人配置信息

如何彻底删除eclipse

windows 2008 r2怎么彻底删除iis和配置文件

彻底删除MySQL

visual studio code安装与彻底删除

【转】彻底删除android studio的安装痕迹