红帽 Linux Redhat6.4安装MySQL 5.1

2022/1/29 19:07:49

本文主要是介绍红帽 Linux Redhat6.4安装MySQL 5.1,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

[root@localhost /]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)

指定yum源,
[root@WebServer ~]# vi /etc/yum.repos.d/rhel-source.repo
区分大小写,不要出错

新建以下内容
固定格式:[rhel-source-local]
给yum源起个名字:name=Red Hat Enterprise Linux 6.4
yrm源地址,挂载到:baseurl=file:///mnt/cdrom/Server
启用状态:enabled=1
软件包签名检查:gpgcheck=1
数字签名的公钥位置:gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

创建目录
[root@localhost /]#mkdir /mnt/cdrom
挂载到,新建目录下
[root@localhost /]#mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/sr0 is write-protected, mounting read-only

这时因为/mnt/cdrom只是一个目录,并不是你要挂载的光驱。
你要挂载光驱的话,应该是:
mount /dev/cdrom /mnt/cdrom
表示将设备/dev/cdrom挂载到/mnt/cdrom这个目录,挂在完成后就可以到/mnt/cdrom下浏览光盘中的文件了。
或者直接使用mount /dev/cdrom也行,Redhat会自动挂将光盘载到/mnt/cdrom上的。

查看挂载是否正确,
[root@localhost dev]# ll /mnt/cdrom/Server/
total 108
-r–r--r–. 2 root root 105446 Jan 31 2013 listing
dr-xr-xr-x. 2 root root 4096 Jan 31 2013 repodata
-r–r--r–. 1 root root 439 Jan 31 2013 TRANS.TBL

列出yum 源
[root@localhost /]#yum repolist
查看 MySQL 相关的包
[root@localhost /]#yum list | grep mysql
安装 MySQL server
[root@localhost /]#yum install -y mysql-server

检查服务
[root@localhost /]#chkconfig
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

配置MySQL 开机自动运行
[root@localhost /]#chkconfig mysqld on

检查服务
[root@localhost /]#chkconfig
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

首次启动MySQL 服务
[root@localhost /]#service mysqld start

Initializing MySQL database: Installing MySQL system tables…
OK
Filling help tables…
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
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.localdomain 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.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]

查看 3306 端口 是否处于监听状态,
[root@localhost /]#netstat -an | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

使用telnet 测试 3306端口,提示:连接失败,是因为防火墙阻止,需要打开防火墙
C:\WINDOWS\system32>telnet 192.168.231.131 3306
正在连接192.168.231.131…无法打开到主机的连接。 在端口 3306: 连接失败

查看防火墙当前设置,
[root@localhost /]#iptables -L

Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all – anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp – anywhere anywhere
ACCEPT all – anywhere anywhere
ACCEPT tcp – anywhere anywhere state NEW tcp dpt:ssh
REJECT all – anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all – anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination

添加 MySQL 防火墙放行动作
[root@localhost /]#iptables -t filter -I INPUT -p tcp --dport 3306 -j ACCEPT

iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp – anywhere anywhere tcp dpt:mysql

使用telnet 测试 防火墙是否放行 MySQL,
C:\WINDOWS\system32>telnet 192.168.231.131 3306
FHost ‘192.168.231.1’ is not allowed to connect to this MySQL server
遗失对主机的连接。
C:\WINDOWS\system32>
虽然没反应,但只要不提示“连接失败”,就说明,没问题

保存对防火墙的设置,否则重新启动后配置丢失,
[root@localhost /]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

至此,完成 红帽系统安装 MySQL 数据库。

January the 29th 2022 Saturday



这篇关于红帽 Linux Redhat6.4安装MySQL 5.1的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程