linux下mysql的卸载、安装全过程

本文介绍如何在Linux环境下卸载和安装MySQL,并详细记录了使用yum命令自动安装MySQL及其相关依赖的过程。此外,还提供了MySQL的安全配置步骤及启动方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

卸载mysql

1、查找以前是否装有mysql

命令:rpm -qa|grep -i mysql

可以看到mysql的包:

mysql-libs-5.1.71-1.el6.x86_64

2、删除mysql

删除命令:rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps

卸载完成

安装mysql

自动下载安装

yum install mysql-server mysql mysql-devel

[hadoop@note1 ~]$ sudo yum install mysql-server mysql mysql-devel
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.neusoft.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.73-7.el6 will be installed
--> Processing Dependency: mysql-libs = 5.1.73-7.el6 for package: mysql-5.1.73-7.el6.x86_64
--> Processing Dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-7.el6.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-7.el6.x86_64
--> Processing Dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-5.1.73-7.el6.x86_64
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: mysql-5.1.73-7.el6.x86_64
---> Package mysql-devel.x86_64 0:5.1.73-7.el6 will be installed
--> Processing Dependency: openssl-devel for package: mysql-devel-5.1.73-7.el6.x86_64
---> Package mysql-server.x86_64 0:5.1.73-7.el6 will be installed
--> Processing Dependency: perl-DBI for package: mysql-server-5.1.73-7.el6.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-7.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.73-7.el6.x86_64
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.73-7.el6 will be installed
---> Package openssl-devel.x86_64 0:1.0.1e-48.el6_8.3 will be installed
--> Processing Dependency: openssl = 1.0.1e-48.el6_8.3 for package: openssl-devel-1.0.1e-48.el6_8.3.x86_64
--> Processing Dependency: zlib-devel for package: openssl-devel-1.0.1e-48.el6_8.3.x86_64
--> Processing Dependency: krb5-devel for package: openssl-devel-1.0.1e-48.el6_8.3.x86_64
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.10.3-57.el6 will be installed
--> Processing Dependency: krb5-libs = 1.10.3-57.el6 for package: krb5-devel-1.10.3-57.el6.x86_64
--> Processing Dependency: libselinux-devel for package: krb5-devel-1.10.3-57.el6.x86_64
--> Processing Dependency: libcom_err-devel for package: krb5-devel-1.10.3-57.el6.x86_64
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.10.3-57.el6.x86_64
---> Package openssl.x86_64 0:1.0.1e-15.el6 will be updated
---> Package openssl.x86_64 0:1.0.1e-48.el6_8.3 will be an update
---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be installed
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.4-5.el6 will be installed
--> Processing Dependency: keyutils-libs = 1.4-5.el6 for package: keyutils-libs-devel-1.4-5.el6.x86_64
---> Package krb5-libs.x86_64 0:1.10.3-10.el6_4.6 will be updated
--> Processing Dependency: krb5-libs = 1.10.3-10.el6_4.6 for package: krb5-workstation-1.10.3-10.el6_4.6.x86_64
---> Package krb5-libs.x86_64 0:1.10.3-57.el6 will be an update
---> Package libcom_err-devel.x86_64 0:1.41.12-22.el6 will be installed
--> Processing Dependency: libcom_err = 1.41.12-22.el6 for package: libcom_err-devel-1.41.12-22.el6.x86_64
---> Package libselinux-devel.x86_64 0:2.0.94-7.el6 will be installed
--> Processing Dependency: libselinux = 2.0.94-7.el6 for package: libselinux-devel-2.0.94-7.el6.x86_64
--> Processing Dependency: libsepol-devel >= 2.0.32-1 for package: libselinux-devel-2.0.94-7.el6.x86_64
--> Processing Dependency: pkgconfig(libsepol) for package: libselinux-devel-2.0.94-7.el6.x86_64
--> Running transaction check
---> Package keyutils-libs.x86_64 0:1.4-4.el6 will be updated
--> Processing Dependency: keyutils-libs = 1.4-4.el6 for package: keyutils-1.4-4.el6.x86_64
---> Package keyutils-libs.x86_64 0:1.4-5.el6 will be an update
---> Package krb5-workstation.x86_64 0:1.10.3-10.el6_4.6 will be updated
---> Package krb5-workstation.x86_64 0:1.10.3-57.el6 will be an update
---> Package libcom_err.x86_64 0:1.41.12-18.el6 will be updated
--> Processing Dependency: libcom_err = 1.41.12-18.el6 for package: e2fsprogs-libs-1.41.12-18.el6.x86_64
--> Processing Dependency: libcom_err = 1.41.12-18.el6 for package: libss-1.41.12-18.el6.x86_64
--> Processing Dependency: libcom_err = 1.41.12-18.el6 for package: e2fsprogs-1.41.12-18.el6.x86_64
---> Package libcom_err.x86_64 0:1.41.12-22.el6 will be an update
---> Package libselinux.x86_64 0:2.0.94-5.3.el6_4.1 will be updated
--> Processing Dependency: libselinux = 2.0.94-5.3.el6_4.1 for package: libselinux-python-2.0.94-5.3.el6_4.1.x86_64
--> Processing Dependency: libselinux = 2.0.94-5.3.el6_4.1 for package: libselinux-utils-2.0.94-5.3.el6_4.1.x86_64
---> Package libselinux.x86_64 0:2.0.94-7.el6 will be an update
---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 will be installed
--> Running transaction check
---> Package e2fsprogs.x86_64 0:1.41.12-18.el6 will be updated
---> Package e2fsprogs.x86_64 0:1.41.12-22.el6 will be an update
---> Package e2fsprogs-libs.x86_64 0:1.41.12-18.el6 will be updated
---> Package e2fsprogs-libs.x86_64 0:1.41.12-22.el6 will be an update
---> Package keyutils.x86_64 0:1.4-4.el6 will be updated
---> Package keyutils.x86_64 0:1.4-5.el6 will be an update
---> Package libselinux-python.x86_64 0:2.0.94-5.3.el6_4.1 will be updated
---> Package libselinux-python.x86_64 0:2.0.94-7.el6 will be an update
---> Package libselinux-utils.x86_64 0:2.0.94-5.3.el6_4.1 will be updated
---> Package libselinux-utils.x86_64 0:2.0.94-7.el6 will be an update
---> Package libss.x86_64 0:1.41.12-18.el6 will be updated
---> Package libss.x86_64 0:1.41.12-22.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================

直到complete

切换到root权限

service mysqld start

或者sudo操作下

[hadoop@note1 ~]$ sudo 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 note1 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  ]


**对MySQL进行安装** 

/usr/bin/mysql_secure_installation

[hadoop@note1 ~]$ /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
… skipping.

By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

MySQL进行登录

[hadoop@note1 ~]$ mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
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>
MySQL就可以正确运行了

Linux状况下也可以开启桌面模式直接进行点击安装更加快捷,包依赖问题都会自动解决,比命令要简单的多。

<think>好的,我需要帮助用户在Linux系统上彻底卸载MySQL并重新安装。首先,我要回忆一下用户提供的引用内容,里面有关于卸载安装MySQL的步骤。用户提到使用rpm命令卸载,删除相关文件和配置文件,还有安装MySQL8.0的方法。另外,用户可能使用的是基于RPM的系统,比如CentOS,或者Debian系的Ubuntu,但引用中有提到Ubuntu的指南,所以可能需要区分不同发行版的命令。 首先,完全卸载MySQL的步骤。根据引用[2]和[3],卸载过程包括停止服务、用rpm命令移除已安装的包,然后删除残留的文件和配置。用户提到要彻底卸载,所以必须确保所有相关的文件和目录都被删除,比如/var/lib/mysql、/etc/my.cnf等。同时,引用[4]提醒步骤可能因版本不同而有所变化,所以需要建议用户参考官方文档。 接下来是安装部分,用户想重新安装MySQL8.0。引用[2]提到查看Linux版本信息,可能需要添加MySQL的官方仓库,然后使用包管理器安装。对于不同的发行版,安装步骤可能不同。例如,Ubuntu可能用apt,而CentOS用yum或dnf。用户提供的引用中有安装MySQL8.0的部分,但具体命令可能需要补充,比如添加仓库、更新包列表等。 用户的问题中还提到“干净重装”,所以需要确保卸载过程中没有遗漏任何文件,否则可能导致重装时出现问题。例如,残留的数据目录可能会影响新安装MySQL。因此,在步骤中需要详细列出所有可能残留的位置,如使用find命令查找mysql相关文件并删除。 另外,需要注意权限问题,卸载和删除某些文件可能需要root权限,所以命令前要加sudo或者以root用户执行。比如停止服务时使用systemctl或service命令,卸载包时使用rpm -e等。 现在需要整理步骤,分卸载安装两部分。卸载部分包括停止服务、卸载包、删除残留文件和配置。安装部分包括添加仓库、安装、启动服务、安全设置等。同时,要针对不同的Linux发行版给出相应的命令,比如Ubuntu和CentOS的区别。 可能遇到的问题:用户可能不清楚自己的Linux发行版,需要提示如何检查版本,比如cat /etc/os-release或lsb_release -a。另外,安装MySQL8.0后,初始密码的位置和如何修改密码也是需要注意的点。 还需要生成相关问题,比如如何验证MySQL是否卸载干净,如何配置MySQL的安全性,或者如何处理依赖问题等。 最后,确保所有命令正确无误,并且按照用户提供的引用内容正确引用来源,比如引用[2]中的卸载步骤,引用[4]中的注意事项等。</think>### 逐步说明:彻底卸载MySQL并进行干净重装 #### 步骤1:停止MySQL服务 在卸载前,先停止正在运行的MySQL服务: ```bash sudo systemctl stop mysqld # 适用于systemd系统(如CentOS 8+/Ubuntu 16.04+) # 或 sudo service mysqld stop # 旧版系统(如CentOS 7) ``` #### 步骤2:卸载MySQL软件包 根据系统包管理器类型选择对应命令: - **RPM系系统(如CentOS/Fedora)** 1. 查询已安装MySQL包: ```bash rpm -qa | grep -i mysql ``` 2. 卸载所有列出的包(替换为实际名称): ```bash sudo rpm -e --nodeps mysql-community-server-8.0.XX mysql-community-client-8.0.XX ... ``` - **Debian系系统(如Ubuntu/Debian)** 1. 卸载MySQL及相关组件: ```bash sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-* ``` 2. 清理残留配置: ```bash sudo apt autoremove sudo apt autoclean ``` #### 步骤3:删除残留文件和目录 手动清除MySQL数据和配置文件: ```bash sudo rm -rf /var/lib/mysql # 数据库文件存储目录 sudo rm -rf /etc/mysql # 配置文件目录 sudo rm -rf /var/log/mysql* # 日志文件 sudo rm -f /etc/my.cnf # 全局配置文件(可能存在) ``` #### 步骤4:确认卸载完成 检查是否残留MySQL相关文件: ```bash sudo find / -name "mysql" # 查找所有残留项并手动删除 ``` --- #### 步骤5:重新安装MySQL 8.0 根据系统选择安装方法: - **RPM系系统(如CentOS)** 1. 添加MySQL官方仓库: ```bash sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm ``` 2. 安装MySQL服务器: ```bash sudo yum install mysql-community-server ``` - **Debian系系统(如Ubuntu)** 1. 下载并添加MySQL APT仓库: ```bash wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb sudo dpkg -i mysql-apt-config_0.8.24-1_all.deb sudo apt update ``` 2. 安装MySQL服务器: ```bash sudo apt install mysql-server ``` #### 步骤6:初始化配置与安全加固 启动服务并设置密码: ```bash sudo systemctl start mysqld # 启动服务 sudo systemctl enable mysqld # 设置开机自启 sudo mysql_secure_installation # 运行安全脚本(设置root密码、删除匿名用户等) ``` --- ### 关键注意事项 1. **卸载彻底性**:务必删除所有配置文件和数据目录,避免旧数据干扰新安装[^2][^4]。 2. **依赖冲突**:安装失败时,检查是否有残留依赖(如`mariadb-libs`),需先卸载[^3]。 3. **防火墙设置**:若需远程访问,开放3306端口: ```bash sudo firewall-cmd --permanent --add-port=3306/tcp # CentOS sudo ufw allow 3306/tcp # Ubuntu ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值