Mysql 卸载 安装 全过程

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

Mysql一个熟悉的概念,一个全新的知识领域。开始我全方位数据库学习之旅。

一切,从安装开始,自己动手每一步。


Linux在安装的过程中,可以勾选Mysql的安装,但是安装的版本是Mysql-5.1.73,版本非常低。必须重新安装,当前最新版本是5.7。但是卸载再安装,明显比空白Linux安装麻烦一点。


下面开始卸载/安装过程。


1. Mysql下载地址

1
https://dev.mysql.com/downloads/file/?id=469494

2. 确认OS版本

1
2
3
# more /etc/issue
CentOS release 6.7 (Final)
Kernel \r  on  an \m
1
2
3
4
5
6
# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.7 (Final)
Release:        6.7
Codename:       Final

3. 根据OS版本,找到需要下载的Mysql版本,右键“将链接另存为”,即可获得下载地址

wKiom1lnJfny6OMnAAFkFpwtApI810.png-wh_50

4. 到Linux下,通过wget下载

1
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.18-1.el6.x86_64.rpm

下面三个rpm包存在依赖关系,也需要下载

1
2
3
# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.18-1.el6.x86_64.rpm
# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.18-1.el6.x86_64.rpm
# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.18-1.el6.x86_64.rpm

5. 检查查询发现,已经安装Mysql-5.1.73,版本非常低。必须重新安装,当前最新版本是5.7

1
2
3
4
5
# rpm -qa | grep mysql
mysql-server-5.1.73-5.el6_6.x86_64
mysql-libs-5.1.73-5.el6_6.x86_64
mysql-5.1.73-5.el6_6.x86_64
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64

6. 准备安装,安装前,就怀疑,会不会覆盖?会不会冲突?安装一下试试,就知道了。

同时安装4个rpm包

1
# rpm -ivh  mysql-community-server-5.7.18-1.el6.x86_64.rpm mysql-community-client-5.7.18-1.el6.x86_64.rpm  mysql-community-common-5.7.18-1.el6.x86_64.rpm mysql-community-libs-5.7.18-1.el6.x86_64.rpm

7. 果然冲突了

1
2
3
4
5
6
7
8
warning: mysql-community-server-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature,  key  ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
file /usr/share/mysql/czech/errmsg.sys  from  install  of  mysql-community-common-5.7.18-1.el6.x86_64 conflicts  with  file  from  package mysql-libs-5.1.73-5.el6_6.x86_64
file /usr/share/mysql/danish/errmsg.sys  from  install  of  mysql-community-common-5.7.18-1.el6.x86_64 conflicts  with  file  from  package mysql-libs-5.1.73-5.el6_6.x86_64
file /usr/share/mysql/dutch/errmsg.sys  from  install  of  mysql-community-common-5.7.18-1.el6.x86_64 conflicts  with  file  from  package mysql-libs-5.1.73-5.el6_6.x86_64
file /usr/share/mysql/english/errmsg.sys  from  install  of  mysql-community-common-5.7.18-1.el6.x86_64 conflicts  with  file  from  package mysql-libs-5.1.73-5.el6_6.x86_64
file /usr/share/mysql/estonian/errmsg.sys  from  install  of  mysql-community-common-5.7.18-1.el6.x86_64 conflicts  with  file  from  package mysql-libs-5.1.73-5.el6_6.x86_64
......

8. 经过查询,也安装失败了,还是5.1.73版本

1
2
3
4
5
# rpm -qa|grep mysql
mysql-server-5.1.73-5.el6_6.x86_64
mysql-libs-5.1.73-5.el6_6.x86_64
mysql-5.1.73-5.el6_6.x86_64
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64

9. 开始卸载原有的5.1.73的Mysql,几种卸载方式,首推YUM方式卸载

1
2
3
# yum remove mysql
# rpm -e mysql  // 普通删除模式 
# rpm -e  --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

10 .还剩余下面两个包

1
2
3
# rpm -qa|grep mysql
mysql-libs-5.1.73-5.el6_6.x86_64
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64

11. 执行yum localinstall安装,发现需要卸载mysql-libs-5.1.73-5.el6_6.x86_64,通过yun卸载这个包后,可以安装了。

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
# yum localinstall mysql-community-server-5.7.18-1.el6.x86_64.rpm mysql-community-client-5.7.18-1.el6.x86_64.rpm mysql-community-common-5.7.18-1.el6.x86_64.rpm  mysql-community-libs-5.7.18-
1.el6.x86_64.rpm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up  Local  Package Process
Examining mysql-community-server-5.7.18-1.el6.x86_64.rpm: mysql-community-server-5.7.18-1.el6.x86_64
Marking mysql-community-server-5.7.18-1.el6.x86_64.rpm  to  be installed
Loading mirror speeds  from  cached hostfile
* base: mirrors.163.com
* extras: mirrors.cn99.com
* updates: mirrors.163.com
Examining mysql-community-client-5.7.18-1.el6.x86_64.rpm: mysql-community-client-5.7.18-1.el6.x86_64
Marking mysql-community-client-5.7.18-1.el6.x86_64.rpm  to  be installed
Examining mysql-community-common-5.7.18-1.el6.x86_64.rpm: mysql-community-common-5.7.18-1.el6.x86_64
Marking mysql-community-common-5.7.18-1.el6.x86_64.rpm  to  be installed
Examining mysql-community-libs-5.7.18-1.el6.x86_64.rpm: mysql-community-libs-5.7.18-1.el6.x86_64
Marking mysql-community-libs-5.7.18-1.el6.x86_64.rpm  to  be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.18-1.el6 will be installed
---> Package mysql-community-common.x86_64 0:5.7.18-1.el6 will be installed
---> Package mysql-community-libs.x86_64 0:5.7.18-1.el6 will be installed
---> Package mysql-community-server.x86_64 0:5.7.18-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================
Package                         Arch            Version               Repository                                             Size
==================================================================================================================================
Installing:
mysql-community-client          x86_64          5.7.18-1.el6          /mysql-community-client-5.7.18-1.el6.x86_64          100 M
mysql-community-common          x86_64          5.7.18-1.el6          /mysql-community-common-5.7.18-1.el6.x86_64          2.5 M
mysql-community-libs            x86_64          5.7.18-1.el6          /mysql-community-libs-5.7.18-1.el6.x86_64            8.9 M
mysql-community-server          x86_64          5.7.18-1.el6          /mysql-community-server-5.7.18-1.el6.x86_64          769 M
Transaction  Summary
==================================================================================================================================
Install       4 Package(s)
Total  size : 880 M
Installed  size : 880 M
Is  this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running  Transaction  Test
Transaction  Test Succeeded
Running  Transaction
Installing : mysql-community-common-5.7.18-1.el6.x86_64                                                                     1/4
Installing : mysql-community-libs-5.7.18-1.el6.x86_64                                                                       2/4
Installing : mysql-community-client-5.7.18-1.el6.x86_64                                                                     3/4
Installing : mysql-community-server-5.7.18-1.el6.x86_64                                                                     4/4
Verifying  : mysql-community-server-5.7.18-1.el6.x86_64                                                                     1/4
Verifying  : mysql-community-libs-5.7.18-1.el6.x86_64                                                                       2/4
Verifying  : mysql-community-common-5.7.18-1.el6.x86_64                                                                     3/4
Verifying  : mysql-community-client-5.7.18-1.el6.x86_64                                                                     4/4
Installed:
mysql-community-client.x86_64 0:5.7.18-1.el6                    mysql-community-common.x86_64 0:5.7.18-1.el6
mysql-community-libs.x86_64 0:5.7.18-1.el6                      mysql-community-server.x86_64 0:5.7.18-1.el6
Complete!

12. 最后检查,已经安装成功

1
2
3
4
5
# rpm -qa|grep mysql
mysql-community-client-5.7.18-1.el6.x86_64
mysql-community-libs-5.7.18-1.el6.x86_64
mysql-community-common-5.7.18-1.el6.x86_64
mysql-community-server-5.7.18-1.el6.x86_64

13. 安装完成,但是启动的时候遇到了问题:

1
2
3
4
5
6
# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Initializing MySQL  database :  2017-07-11T15:23:50.462866Z 0 [Warning]  TIMESTAMP  with  implicit  DEFAULT  value  is  deprecated. Please use  --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-11T15:23:50.465315Z 0 [ERROR]  --initialize specified but the data directory has files in it. Aborting.
2017-07-11T15:23:50.465365Z 0 [ERROR] Aborting
[FAILED]

14. 百度的解决方法(是由于之前老版本的数据库已经占用这个文件夹,需要清空,或者在/etc/my.cnf中重新指定--datadir

保证 --datadir目录为空。 /usr/local/var/mysql 这个目录


15. 启动成功

1
2
3
4
5
6
7
8
9
# cd /var/lib/mysql
# ls
auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1
# rm *
rm: remove regular file `auto.cnf '? y
rm: remove regular file `ib_buffer_pool' ? y
rm: remove regular file `ibdata1 '? y
rm: remove regular file `ib_logfile0' ? y
rm: remove regular file `ib_logfile1'? y

# service mysqld restart

1
2
3
4
Stopping mysqld:                                           [  OK  ]
Initializing MySQL  database :                               [  OK  ]
Installing validate  password  plugin:                       [  OK  ]
Starting mysqld:                                           [  OK  ]

# ps -ef|grep mysql

1
2
3
root      4533     1  0 23:25 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe  --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql     4727  4533  4 23:25 pts/0    00:00:00 /usr/sbin/mysqld  --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root      4762  3752  0 23:25 pts/0    00:00:00 grep mysql

16. 然而启动的过程中,又遇到一些问题,密码不知道了,重置密码

1
2
3
4
5
# mysql -u root
ERROR 1045 (28000): Access denied  for  user  'root' @ 'localhost'  (using  password NO )
[root@test mysql]# mysql -u root -p
Enter  password :
ERROR 1045 (28000): Access denied  for  user  'root' @ 'localhost'  (using  password : YES)

编辑mysql配置文件/etc/my.cnf,在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql

# vi /etc/my.cnf

1
2
3
[root@test mysql]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

# mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Welcome  to  the MySQL monitor.  Commands  end  with  or  \g.
Your MySQL  connection  id  is  4
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> show databases;
+ --------------------+
Database            |
+ --------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+ --------------------+
rows  in  set  (0.00 sec)

设置密码,然后删除/etc/my.cnf中的 skip-grant-tables

再次重启mysql

1
2
mysql> use mysql;
Database  changed

--.给root用户设置新密码: 

5.7版本之前:

1
2
3
mysql>  update  user  set  password = password ( "新密码" where  user = "root" ;
Query OK, 1  rows  affected (0.01 sec)
Rows  matched: 1 Changed: 1 Warnings: 0

在5.7版本之后,mysql数据库下已经没有password这个字段了,password字段改成了authentication_string。

1
update  mysql. user  set  authentication_string= PASSWORD ( 'oracle' where  User = 'root' ;
1
2
mysql> flush  privileges ;
Query OK, 0  rows  affected (0.00 sec)

---退出mysql,重启然后重新登录

1
2
3
# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

# mysql -uroot -poracle

1
2
3
4
5
6
7
8
9
10
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  5
Server version: 5.7.18
Copyright (c) 2000, 2017, 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>










本文转自 hsbxxl 51CTO博客,原文链接:http://blog.51cto.com/hsbxxl/1947164,如需转载请自行联系原作者

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
14天前
|
安全 关系型数据库 MySQL
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
94 16
|
30天前
|
关系型数据库 MySQL 数据库
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
在这一章节,主要介绍两个部分,数据库相关概念及MySQL数据库的介绍、下载、安装、启动及连接。接着,详细描述了MySQL 8.0的版本选择与下载,推荐使用社区版(免费)。安装过程包括自定义安装路径、配置环境变量、启动和停止服务、以及客户端连接测试。此外,还提供了在同一台电脑上安装多个MySQL版本的方法及卸载步骤。最后,解释了关系型数据库(RDBMS)的特点,即基于二维表存储数据,使用SQL语言进行操作,格式统一且便于维护。通过具体的结构图展示了MySQL的数据模型,说明了数据库服务器、数据库、表和记录之间的层次关系。
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
|
23天前
|
NoSQL 关系型数据库 Redis
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
93 14
|
20天前
|
关系型数据库 MySQL 应用服务中间件
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
77 7
|
1月前
|
关系型数据库 MySQL 数据库
docker高级篇(大厂进阶):安装mysql主从复制
docker高级篇(大厂进阶):安装mysql主从复制
120 24
|
26天前
|
安全 关系型数据库 MySQL
Windows Server 安装 MySQL 8.0 详细指南
安装 MySQL 需要谨慎,特别注意安全配置和权限管理。根据实际业务需求调整配置,确保数据库的性能和安全。
150 9
|
30天前
|
NoSQL 关系型数据库 MySQL
Linux安装jdk、mysql、redis
Linux安装jdk、mysql、redis
182 7
|
2月前
|
SQL 关系型数据库 MySQL
go语言数据库中mysql驱动安装
【11月更文挑战第2天】
103 4
|
2月前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。通过具体案例,读者可以了解如何准备环境、下载源码、编译安装、配置服务及登录 MySQL。编译源码安装虽然复杂,但提供了更高的定制性和灵活性,适用于需要高度定制的场景。
163 3
|
2月前
|
运维 关系型数据库 MySQL
安装MySQL8数据库
本文介绍了MySQL的不同版本及其特点,并详细描述了如何通过Yum源安装MySQL 8.4社区版,包括配置Yum源、安装MySQL、启动服务、设置开机自启动、修改root用户密码以及设置远程登录等步骤。最后还提供了测试连接的方法。适用于初学者和运维人员。
255 0