0112centos上面l安装卸载mysq

http://www.centoscn.com/CentosServer/sql/2015/0409/5127.html
常用命令
cat /etc/issue
rpm -qa | grep mysql
yum -y remove mysql-libs-5.1*
rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm
rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm
rpm -ivh MySQL-devel-5.6.21-1.rhel5.x86_64.rpm
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
/usr/bin/mysql_install_db
ps -ef | grep mysql
chkconfig mysql on
chkconfig mysql --list

忘记mysql密码,CentOS下设置Mysql的root密码
/etc/init.d/mysql stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -u root mysql
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
FLUSH PRIVILEGES;
exit;
/etc/init.d/mysql restart

 

如何确定mysql使用哪个配置文件

mysql --help | grep 'Default options' -A 1
按照上面顺序一样,mysql会依序的去这些位置找my.cnf文件的,没有就下一个。
whereis my.cnf可以查看哪些地方有该文件

 

开启mysql 3306访问端口

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables status
即可


-- 卸载mysql

1: 检查是否安装了MySQL组件。

[root@DB-Server init.d]# rpm -qa | grep -i mysql
 
MySQL-devel-5.6.23-1.linux_glibc2.5
 
MySQL-client-5.6.23-1.linux_glibc2.5
 
MySQL-server-5.6.23-1.linux_glibc2.5
 

clip_image001

如上所示,说明安装了MySQL 5.6.23这个版本的client、server、devel三个组件。

 

2: 卸载前关闭MySQL服务

 

2.1 方法1

[root@DB-Server init.d]# service mysql status
 MySQL running (25673)[  OK  ]
[root@DB-Server init.d]# service mysql stop
 Shutting down MySQL..[  OK  ]
[root@DB-Server init.d]# service mysql status
 MySQL is not running[FAILED]

clip_image002

 

2.2 方法2

[root@DB-Server init.d]# ./mysql status
 MySQL running (26215)[  OK  ]
[root@DB-Server init.d]# ./mysql stop
 Shutting down MySQL..[  OK  ]
[root@DB-Server init.d]# ./mysql status
 MySQL is not running[FAILED]
[root@DB-Server init.d]# 

clip_image003

[root@DB-Server init.d]# chkconfig --list | grep -i mysql
 
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
 
[root@DB-Server init.d]# 
 

 

3. 收集MySQL对应的文件夹信息

[root@DB-Server init.d]# whereis mysql

mysql: /usr/bin/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

最好实用find命令查看MySQL数据库相关的文件,方便后面彻底删除MySQL。

[root@DB-Server init.d]# find / -name mysql
/etc/rc.d/init.d/mysql
/etc/logrotate.d/mysql
/var/lock/subsys/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/include/mysql
/usr/include/mysql/mysql
/usr/bin/mysql
/usr/share/mysql
/usr/lib64/mysql

clip_image004

 

4: 卸载删除MySQL各类组件

[root@DB-Server init.d]# 
[root@DB-Server init.d]# rpm -ev MySQL-devel-5.6.23-1.linux_glibc2.5
[root@DB-Server init.d]# rpm -ev MySQL-server-5.6.23-1.linux_glibc2.5
You have new mail in /var/spool/mail/root
[root@DB-Server init.d]# rpm -ev MySQL-client-5.6.23-1.linux_glibc2.5
[root@DB-Server init.d]#

clip_image005

 

5:删除MySQL对应的文件夹

 

检查各个MySQL文件夹是否清理删除干净。

[root@DB-Server init.d]# whereis mysql
mysql:
[root@DB-Server init.d]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
[root@DB-Server init.d]# rm -rf /var/lib/mysql
[root@DB-Server init.d]# rm -rf /var/lib/mysql/mysql
[root@DB-Server init.d]# rm -rf /usr/lib64/mysql
[root@DB-Server init.d]# 

6:删除mysql用户及用户组

如果有必要,删除mysql用户以及mysql用户组。

[root@DB-Server ~]# more /etc/passwd | grep mysql
mysql:x:101:501::/home/mysql:/bin/bash
[root@DB-Server ~]# more /etc/shadow | grep mysql
mysql:!!:16496::::::
[root@DB-Server ~]# more /etc/group | grep mysql
mysql:x:501:
[root@DB-Server ~]# userdel mysql
[root@DB-Server ~]# groupdel mysql
groupdel: group mysql does not exist
[root@DB-Server ~]# 

 

7:确认MySQL是否卸载删除

[root@DB-Server init.d]# rpm -qa | grep -i mysql

 

-- 转自http://www.cnblogs.com/kerrycode/p/4364465.html

posted @ 2017-01-12 18:10  秦楚风  阅读(212)  评论(0编辑  收藏  举报