centos7安装卸载mysql

VMware虚拟机装好后,再装个CentOS7系统,以上环境自行百度...

一、Linux下查看mysql是否安装

1、指令ps -ef|grep mysql

[root@localhost 桌面]# ps -ef|grep mysql
mysql 2688 1 0 13:31 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 2857 2688 0 13:31 ? 00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 4326 4294 0 13:39 pts/0 00:00:00 grep --color=auto mysql/

2、rpm -qa | grep mysql

[root@localhost 桌面]# rpm -qa | grep mysql
mysql-community-libs-5.6.36-2.el7.x86_64
mysql-community-release-el7-5.noarch
mysql-community-server-5.6.36-2.el7.x86_64
mysql-community-client-5.6.36-2.el7.x86_64
mysql-community-devel-5.6.36-2.el7.x86_64
mysql-community-common-5.6.36-2.el7.x86_64

3、mysql的守护进程是mysqld

如果已经安装:

[root@localhost 桌面]#  service mysqld start 
Redirecting to /bin/systemctl start  mysqld.service

如果没有安装:

[root@localhost 桌面]# service mysqld start 
mysqld:未被识别的服务

 

二、如果没有安装过mysql

centos7不支持mysql,内部集成了mariadb,而安装mysql的话会和mariadb文件冲突,所以需要先卸载mariadb,以下为卸载mariadb,安装mysql的步骤

  

#列出所有被安装的rpm package 
rpm -qa | grep mariadb

#卸载
rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64

1、下载mysql的repo源 ,下载地址 http://download.csdn.net/detail/xuxiaoyu__/9890496,把这个安装文件拖到linux可视化界面上,

2、安装rpm包,执行安装命令:

[root@localhost 桌面]# rpm -ivh /home/xuxiaoyu/桌面/mysql-community-release-el7-5.noarch.rpm  (回车)

 准备中... ################################# [100%]
 软件包 mysql-community-release-el7-5.noarch 已经安装

3、安装myslq:yum install mysql-server(如果不成功,就操作步骤4)

4、使用yum安装mysql数据库(在操作之前我先执行了这个命令,因为刚开始装mysql时,各种错,就按着网上说的去试了 yum install -y perl perl-devela)

输入:yum -y install mysql-server mysql mysql-devel ,命令将:mysql-server、mysql、mysql-devel都安装好,当结果显示为“Complete!”即安装完毕。

注:安装mysql只是安装了数据库,只有安装mysql-server才相当于安装了客户端。

三、安装成功后对mysql的相关操作

启动mysql:systemctl start mysqld.service

结束:systemctl stop mysqld.service

重启:systemctl restart mysqld.service

连接mysql,进入mysql dos,一开始安装是不需要密码的,回车一下就行(输入exit,回车,退出mysql dos),出现以下页面,说明mysql安装成功,完全可以正常使用!

(参考:http://www.360doc.com/content/16/0617/21/8357485_568631202.shtml)

[root@localhost 桌面]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.36 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> 

四、其他:

1、杀掉yum进程:rm -f /var/run/yum.pid

2、ctrl+alt+F1/F2 虚拟机可视化界面和dos命令相互切换

3、虚拟机锁屏时,直接输入密码即可解锁


#################CentOS7下MySQL的卸载####################

1:查看MySQL是否安装:

 方式1:

[root@localhost usr]# yum list installed mysql*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.yun-idc.com
 * extras: mirror.neu.edu.cn
 * updates: mirrors.yun-idc.com
Installed Packages
MySQL-client.x86_64   5.6.27-1.el6    installed
MySQL-devel.x86_64    5.6.27-1.el6    installed
MySQL-server.x86_64   5.6.27-1.el6    installed
[root@localhost usr]#

 

方式2( -i  :不区分大小写):

[root@localhost usr]# rpm -qa | grep -i mysql
MySQL-server-5.6.27-1.el6.x86_64
MySQL-client-5.6.27-1.el6.x86_64
MySQL-devel-5.6.27-1.el6.x86_64
[root@localhost usr]# 

2:卸载MySQL:

卸载1:

[root@localhost usr]# yum remove mysql mysql-server mysql-libs compat-mysql51
[root@localhost usr]# rm -rf /var/lib/mysql
[root@localhost usr]# rm /etc/my.cnf

如果装了mysql-devel(其他一样add command),卸载为:

[root@Tony_ts_tian init.d]# yum remove mysql mysql-devel mysql-server mysql-libs compat-mysql51

注(例如):

mysql-5.5.39-1.el6.remi.x86_64
mysql-libs-5.5.39-1.el6.remi.x86_64
compat-mysql51-5.1.54-1.el6.remi.x86_64
mysql-server-5.5.39-1.el6.remi.x86_64
卸载2{继续,1,2选择一种(此处为介绍):}:
[root@localhost mysql]# rpm -aq | grep -i mysql
MySQL-server-5.6.27-1.el6.x86_64
MySQL-client-5.6.27-1.el6.x86_64
MySQL-devel-5.6.27-1.el6.x86_64
[root@localhost mysql]# rpm -e MySQL-server-5.6.27-1.el6.x86_64
[root@localhost mysql]# rpm -e MySQL-client-5.6.27-1.el6.x86_64
[root@localhost mysql]# rpm -e MySQL-devel-5.6.27-1.el6.x86_64
[root@localhost rc.d]# cd /var/lib/
[root@localhost lib]# rm -rf mysql/
注:删除MySQL数据库目录(关键) ,否则password不更新(默认安装,如果自定义安装路径和链接路径ln -s ……请删除。)
   rm -rf /var/lib/mysql
卸载3:
[root@localhost usr]# whereis mysql
mysql: /usr/lib64/mysql
[root@localhost usr]# rm -rf /usr/lib64/mysql
注:find / -name mysql
注:清空相关mysql的所有目录以及文件和其他配置和设置等。如果有,则删除。也必须考虑其他软件不去影响。
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
卸载4
[root@localhost usr]# rm –rf /usr/my.cnf
[root@localhost usr]# rm -rf /root/.mysql_sercret 
卸载5(自启服务):
[root@localhost usr]# chkconfig --list | grep -i mysql
[root@localhost usr]# chkconfig --del mysqld
此处删除看自己设置:mysql/mysqld 

CentOS7 下安装 mysql 涉及到的命令

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值