通过rpm安装mysql_RedHat下通过rpm安装Mysql

之前在Linux装过很多次MySQL,每次安装都多少有些坎坷,平时也比较懒,没有做过这方面的总结,今天将安装过程中遇到的问题总结出来,以供后续参考。

MySQL被分解成了很多个不同的RPM软件包,如果不使用Linux系统自带的MySQL,需要下载MySQL四个比较重要的RPM包,分别是:主服务包(mian server package)、客户端包(client package)、共享组件包(shared component package)和开发包(development package),当然本文只需要用到前两个包即可。

一、环境

1. Red Hat Enterprise Linux 6.2 64 位

2. MySQL 5.5.19

二、下载

从Mysql官网下载需要的版本 http://downloads.mysql.com/archives/community/

本文安装文件为:MySQL-server-5.5.19-1.el6.x86_64.rpm

MySQL-client-5.5.19-1.el6.x86_64.rpm

三、安装过程

1.  检查系统是否安装Mysql

rpm -qa|grep mysql

需要注意的是,Linux对于大小写敏感,因此可以加入参数-i忽略大小写

rpm -qa|grep -i mysql

执行命令得到如下结果:

[root@localhost ~]# rpm -qa|grep mysql

mysql-libs-5.1.52-1.el6_0.1.x86_64

因此需要将mysql-libs-5.1.52-1.el6_0.1.x86_64删除。

2. 检查是否存在mysql的进程

[root@localhost mysql]# ps -ef|grep mysql

如果存在mysql进程,如上,则通过以下命令杀掉:

kill -9 进程号

3. 删除已存在的Mysql

rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64

执行命令得到如下结果:

[root@localhost ~]# rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64

error: Failed dependencies:

libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64

libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64

mysql-libs is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64

根据错误提示是因为存在包之间的依赖关系,要删除mysql-libs之前必须删除postfix,如是接着执行命令删除postfix,得到如下提示:

[root@localhost ~]# rpm -e postfix

error: Failed dependencies:

/usr/sbin/sendmail is needed by (installed) cronie-1.4.4-7.el6.x86_64

/usr/sbin/sendmail is needed by (installed) redhat-lsb-4.0-3.el6.x86_64

又有更多的依赖了,因此决定采用其他方式处理这个问题,在删除mysql-libs的时候加上不检查依赖的参数--nodeps,成功删除。

[root@localhost ~]# rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64 --nodeps

PS:如果是再次安装,需要注意通过find命令查找mysql,将查询到的所有文件加删掉,同时etc如果存在my.cf,删掉,检查etc/init.d和etc/rc.d/init.d下是否存在mysql相关的东西,都删掉。

4. 安装mysql服务端

rpm -ivh MySQL-server-5.5.19-1.el6.x86_64.rpm

执行上述命令,得到结果如下:

[root@localhost mysql]# rpm -ivh MySQL-server-5.5.19-1.el6.x86_64.rpm

Preparing...                ########################################### [100%]

1:MySQL-server           ########################################### [100%]

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 localhost.xd 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.

Please report any problems with the /usr/bin/mysqlbug script!

分析结果,安装很顺利,但是貌似在结尾没有启动服务。。。

5.  检查是否启动Mysql服务

很据上一步的判断,需要验证下猜想,先通过以下两个命令判断:

[root@localhost mysql]# ps -ef|grep mysql

root      4032  3712  0 19:58 pts/2    00:00:00 grep mysql

[root@localhost mysql]# netstat -nap|grep 3306

第一个命令判断当前系统中是否存在mysql进程,得到结果是没有进程。

第二个命令是判断3306端口是否启动,也没有得到结果。

因此得出结论,mysql服务未启动。

6.  检查mysql服务端是否安装成功

通过find命令查找是否存在mysql相关的文件

[root@localhost mysql]# find / -name mysql

/var/lib/mysql

/var/lib/mysql/mysql

/usr/lib64/mysql

/usr/mysql

/usr/share/mysql

/etc/rc.d/init.d/mysql

/etc/logrotate.d/mysql

然后通过rpm验证

[root@localhost mysql]# rpm -qa|grep -i mysql

MySQL-server-5.5.19-1.el6.x86_64

可以得出结论,服务端安装成功,但是服务未启动。

7. 安装mysql客户端并验证

[root@localhost mysql]# rpm -ivh MySQL-client-5.5.19-1.el6.x86_64.rpm

Preparing...                ########################################### [100%]

1:MySQL-client           ########################################### [100%]

[root@localhost mysql]# rpm -qa|grep MySQL

MySQL-client-5.5.19-1.el6.x86_64

MySQL-server-5.5.19-1.el6.x86_64

8. 试探未启动服务前登录报错

在服务未启动之前执行mysql命令,查看报错信息:

[root@localhost mysql]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

9. 启动mysql服务

service mysql start

执行结果如下:

[root@localhost mysql]# service mysql start

Starting MySQL...                                          [  OK  ]

[root@localhost mysql]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.19 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>

10. 至此启动成功,检查相关的进程和端口

[root@localhost mysql]# netstat -nap|grep 3306

tcp        0      0 0.0.0.0:3306                0.0.0.0:*          LISTEN      4247/mysqld

[root@localhost mysql]# ps -ef|grep mysql

root     28355     1  0 20:52 pts/2    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.xd.pid

mysql    28432 28355  0 20:52 pts/2    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.xd.err --pid-file=/var/lib/mysql/localhost.xd.pid

root     29994  3712  0 21:47 pts/2    00:00:00 grep mysql

11. 通过远程访问数据库

通过远程访问安装好的mysql数据库,发现报错:

Error No. 2003 Can't connect to MySql server on '192.168.255.133'(10065)

考虑到redhat的防火墙,因此将系统防火墙关闭,再次远程登录,仍然报错:

Error No. 1130 Host'192.168.255.133' is not allowed to connect to this MySQL server

因为mysql默认是不允许远程访问数据库服务器的,所以需要进行mysql更改。

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select host,user from user;

+--------------+------+

| host         | user |

+--------------+------+

| 127.0.0.1    | root |

| ::1          | root |

| localhost    |      |

| localhost    | root |

| localhost.xd |      |

| localhost.xd | root |

+--------------+------+

6 rows in set (0.00 sec)

mysql> update mysql.user set host='%' where host='localhost' and user='root';

Query OK, 1 row affected (0.22 sec)

Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;

重新远程登录成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值