天天看点

centos 5.5 安装mysql 5.5 全程详细记录 RPM方式安装

#rpm –qa|grep –i mysql查看已安装的mysql版本

如果有已存在的mysql版本则删除

安装服务端和客户端,去ORACLE官网下载:

# rpm -ivh MySQL-server-5.5.28-1.linux2.6.i386.rpm

# rpm -ivh MySQL-client-5.5.28-1.linux2.6.i386.rpm

安装后会出现以下信息,提示不要忘记设计root用户的密码以及其他信息。

之后查看mysql的服务是否启动#netstat -nat

如看到有3306的端口号,就说明服务启动了,默认的端口是3306 ,如果没有启动的话 ,就打开服务 #service mysql start 启动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数据库后:mysql>use mysql;

然后查看一下root的情况select user,password form user;

修改密码update user set password=password(‘newpassword’)where user=’root’ and host=’root’ or host=’localhost’;

至此mysql是安装成功了的。

但是远程访问还是不行的,还有两个地方,第一是数据库设置,第二是防火墙。一般数据库已经是可以直接连接成功的了。只是没有ROOT权限,如果连不上,像我这样的,肯定是被防火墙挡住了。

数据库的MYSQL表中控制的可来访的权限,因此我们要改一下它,这样我们就有ROOT权限了。

修改一个root用户的host为你的ip地址

update user u set u.host = 'your_ipaddress' where u.user = root and u.host = 'localhost';

update user u set u.host = '192.168.1.42' where u.user = root and u.host = 'localhost';

或干脆

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

重启服务:service mysql restart

加了密码以后,主机现在不能用MYSQL命令直接进去了。需要打成MYSQL -P ,然后可以输你刚才更新的密码才可以进。

然后是最吭爹的防火墙,我被它卡了很久。

设置CentOS防火墙开放端口方法如下:

打开iptables的配置文件:vi /etc/sysconfig/iptables

在一大串-A RH-Firewall-1-INPU。。。。。的后面添加:-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

或是直接复制有一个控制22端口的,粘一下,直接改成3306也省事。

重启防火墙就可以了。

暂停iptables服务

# service iptables stop

重启iptables服务

# service iptables start