系统:centos 5.5 32位系统一、卸载1、查找以前是否装有mysql[iyunv@tom-86-old38 mysql]# rpm -qa|grep -i mysql
perl-DBD-MySQL-3.0007-2.el5
mysql55-mysql-5.5.45-1.el5
mysql55-runtime-1-12.el5
mysql55-mysql-server-5.5.45-1.el5
libmysqlclient15-5.0.95-5.w5
mysql55-1-12.el5
mysql55-mysql-libs-5.5.45-1.el5
2、停止mysql服务、删除之前安装的mysql[iyunv@tom-86-old38 mysql]# rpm -ev mysql55-1-12.el5
[iyunv@tom-86-old38 mysql]# rpm -ev mysql55-mysql-server-5.5.45-1.el5
[iyunv@tom-86-old38 mysql]# rpm -ev mysql55-mysql-5.5.45-1.el5
[iyunv@tom-86-old38 mysql]# rpm -ev mysql55-mysql-libs-5.5.45-1.el5.i386
[iyunv@tom-86-old38 mysql]# rpm -ev perl-DBD-MySQL-3.0007-2.el5.i386
[iyunv@tom-86-old38 mysql]# rpm -ev libmysqlclient15-5.0.95-5.w5
3、查找之前老版本mysql的目录、并且删除老版本mysql的文件和库[iyunv@tom-86-old38 mysql]# find / -name mysql
/opt/rh/mysql55/root/var/lib/mysql
/opt/rh/mysql55/root/var/lib/mysql/mysql
/usr/local/php-5.4.13/ext/mysql
/usr/lib/mysql
/usr/bin/mysql
/usr/mysql
删除:
[iyunv@tom-86-old38 mysql]# rm -rf /opt/rh/mysql55/root/var/lib/mysql
[iyunv@tom-86-old38 mysql]# rm -rf /opt/rh/mysql55/root/var/lib/mysql/mysql
[iyunv@tom-86-old38 mysql]# rm -rf /usr/local/php-5.4.13/ext/mysql
[iyunv@tom-86-old38 mysql]# rm -rf /usr/lib/mysql
[iyunv@tom-86-old38 mysql]# rm -rf /usr/bin/mysql
[iyunv@tom-86-old38 mysql]# rm -rf /usr/mysql
网上说下面这个文件需要手动删除,但我这没这个文件~
/etc/my.cnf
4、再次查找机器是否安装mysqlrpm -qa|grep -i mysql
无结果,说明已经卸载彻底、接下来直接安装mysql即可
二、安装
1、文件下载
新建/usr/local/mysql目录
[iyunv@tom-86-old38 local]# mkdir mysql
在当前目录下载文件
分别下载以下三个文件(由于我的机器是32位,下面是32位版本的包,如果你的机器是64位的请下载64位版本):
MySQL-server-5.5.16-1.rhel5.i386.rpm
MySQL-client-5.5.16-1.rhel4.i386.rpm
MySQL-devel-5.5.16-1.rhel4.i386.rpm
在这里使用wget命令使用断点传输的方式将这三个文件下载[iyunv@tom-86-old38 mysql]# wget -c http://dev.mysql.com/get/Downloa ... ://mysql.spd.co.il/
[iyunv@tom-86-old38 mysql]# wget -c http://dev.mysql.com/get/Downloa ... ://mysql.spd.co.il/
[iyunv@tom-86-old38 mysql]# wget -c http://dev.mysql.com/get/Downloa ... ://mysql.spd.co.il/
2、文件安装
[iyunv@tom-86-old38 mysql]# rpm -ivh MySQL-server-5.5.16-1.rhel4.i386.rpm MySQL-client-5.5.16-1.rhel4.i386.rpm MySQL-devel-5.5.16-1.rhel4.i386.rpm
rpm包安装的MySQL是不会安装/etc/my.cnf文件的,解决方法,只需要复制/usr/share/mysql目录下的my-huge.cnf 文件到/etc目录,并改名为my.cnf即可
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
3、启动mysql
[iyunv@tom-86-old38 mysql]# /etc/init.d/mysql start
Starting MySQL.. [确定]
4、测试进入mysql,修改root密码为123456
[iyunv@tom-86-old38 mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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> UPDATE mysql.user SET password=PASSWORD('123456') WHERE User='root';
mysql> FLUSH PRIVILEGES;
5、新建用户,修改端口
grant ALL PRIVILEGES on *.* to 'zan365'@'%' identified by 'my...'; #所有数据库,所有权限,所有远程地址
grant ALL PRIVILEGES on *.* to 'zan365'@localhost identified by 'my...'; #所有数据库,所有权限,控制台
FLUSH PRIVILEGES;
修该mysql端口
编辑/etc/my.cnf,修改端口,
port=3306 (将3306改成你想要的)/etc/init.d/mysql stop
/etc/init.d/mysql start
开起系统防火墙端口。
vi /etc/sysconfig/IPtables
添加-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT #(将3306改成你想要的)(注意添加在-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited之前,否则可能导致规则不生效)
重启防火墙/etc/init.d/iptables restart