博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux CentOS6.5 yum安装mysql 5.6(转载&删改)
阅读量:7230 次
发布时间:2019-06-29

本文共 3298 字,大约阅读时间需要 10 分钟。

按:下面文章经过我一路测试没有问题,是篇好文,在此感谢作者   。另因原文有些啰嗦,我自己有所删改,并尾后增加了一大段。

出处:https://www.cnblogs.com/renjidong/p/7047396.html

1.先检测系统是否自带安装mysql

# yum list installed | grep mysql

 

2.如果发现有系统自带mysql,删除之

# yum -y remove mysql-libs.x86_64

3.从网络获取mysql5.6(79M),解释一下,这个rpm还不是mysql的安装文件,只是两个yum源文件

# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

4.接着执行这句,执行后在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo

# rpm -ivh mysql-community-release-el6-5.noarch.rpm

5.这个时候,可以用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件

#yum repolist all | grep mysql

6.安装mysql 服务器命令(一路yes):

# yum install mysql-community-server

7.安装成功后,启动mysql

# service mysqld start

8.由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码

# mysql -u root

mysql> use mysql;
mysql> update user set password=PASSWORD('123456') where User='root';
mysql> flush privileges;

9.查看mysql是否自启动,并且设置开启自启动命令

# chkconfig --list | grep mysqld

# chkconfig mysqld on

10.mysql安全设置(系统会一路问你几个问题,基本上一路yes):

# mysql_secure_installation

 

以下为我个人添加的内容:

进入mysql数据库管理控制台,让远程可以访问。

#mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.67 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> grant all privileges on *.* to root@'%' identified by "root";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

上面的步骤是进行授权

然后重启mysqld服务

service mysqld restart
Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]

再次进入mysql管理控制台(修改密码这一步不可或缺,否则容易出现“access denied for user root @localhost”错误

mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.67 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
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> update user set password=password('12345678') where user='root';
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5  Changed: 5  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

以上步骤是修改root用户的密码

之后开启防火墙的3306端口

vi /etc/sysconfig/iptables
以下是/etc/sysconfig/iptables的内容,其中蓝色一行是新加的。这一行可以由上一行复制得到,方法是在22哪行按下yy进行行复制,然后按p进行粘贴,然后点insert键进入编辑模式,修改22为3306,然后点esc,输入wq保存退出。
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

防火墙重启

service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

之后就可以在终端上敲#ifconfig,找出虚拟机对应的ip地址,比如说是192.168.0.100,然后就可以用mysql-front或程序连接数据库了。

 2018年3月25日14点41分

你可能感兴趣的文章
强大的vim配置文件,让编程更随意
查看>>
崛起于Springboot2.X之配置文件详解(10)
查看>>
定时执行程序-Quartz简单实例
查看>>
【CF 应用开发大赛】MyfCMS系统
查看>>
windows下kangle虚拟主机-架设java空间的教程及心得
查看>>
Discuz! X2.5:文件目录结构
查看>>
我的友情链接
查看>>
TCP/IP协议及首部初了解
查看>>
防火墙iptables
查看>>
CUDA搭建
查看>>
memcached与PostgreSQL缓存命中机制
查看>>
百度地图路线检索(3)
查看>>
linux netstat 命令详解
查看>>
对前几篇blog的环境等的补充说明
查看>>
Curl命令使用解析大全
查看>>
MySQL日期函数
查看>>
【00】Effective Java
查看>>
.NET重构—单元测试重构
查看>>
SMB简介sabma服务(一)
查看>>
ANT简明教程
查看>>