centos7安装卸载mysql

来源:互联网 发布:linux 随机启动脚本 编辑:程序博客网 时间:2024/06/11 17:01

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

一、Linux下查看mysql是否安装

1、指令ps -ef|grep mysql

[root@localhost 桌面]# ps -ef|grep mysqlmysql 2688 1 0 13:31 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usrmysql 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.sockroot 4326 4294 0 13:39 pts/0 00:00:00 grep --color=auto mysql/

2、rpm -qa | grep mysql

[root@localhost 桌面]# rpm -qa | grep mysqlmysql-community-libs-5.6.36-2.el7.x86_64mysql-community-release-el7-5.noarchmysql-community-server-5.6.36-2.el7.x86_64mysql-community-client-5.6.36-2.el7.x86_64mysql-community-devel-5.6.36-2.el7.x86_64mysql-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 -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.yun-idc.com * extras: mirror.neu.edu.cn * updates: mirrors.yun-idc.comInstalled PackagesMySQL-client.x86_64   5.6.27-1.el6    installedMySQL-devel.x86_64    5.6.27-1.el6    installedMySQL-server.x86_64   5.6.27-1.el6    installed[root@localhost usr]#

 

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

[root@localhost usr]# rpm -qa | grep -i mysqlMySQL-server-5.6.27-1.el6.x86_64MySQL-client-5.6.27-1.el6.x86_64MySQL-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 mysqlMySQL-server-5.6.27-1.el6.x86_64MySQL-client-5.6.27-1.el6.x86_64MySQL-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 mysqlmysql: /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 涉及到的命令

原创粉丝点击