centos7安装mysql5

centos7安装mysql5.7

1、检查机器里是否有mysql或者mariadb

rpm -qa | grep mysql
rpm -qa | grep mariadb

2、如果有则卸载原来的版本

rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

3、常用命令

#ps:
rpm -qa 列出所有已安装软件包
rpm -e packagename  删除软件包
rpm -e --nodeps packagename  强制删除软件和依赖包
rpm -q 包名     查询包是否安装
rpm -ivh 包名     安装软件包

4、官网下载rpm包

mysql官方有好多linux版本,但是没有centos的,应该选择Red Hat Enterprise Linux / Oracle Linux 版本,centos7则选择Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit) ,下载mysql-5.7.24-1.el7.x86_64.rpm-bundle.tar ,解压。

5、安装rpm包

将下载好的rpm包上传到服务器,然后按common --> libs --> clients --> server 顺序安装。

rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-clients-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm

可能出现错误

# error: Failed dependencies: \
        libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.19-1.el6.x86_64 \
        libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.19-1.el6.x86_64 \
        libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.19-1.el6.x86_64
 
解决方法:
 
$ yum install -y numactl

6、安装服务

yum install mysql-server

7、启动服务

systemctl start mysqld

8、登录并设置密码

5.7版本默认对于root帐号有一个随机密码,可以通过 grep "password" /var/log/mysqld.log获得,broot@localhost: 此处为随机密码
运行mysql -uroot -p 回车
粘贴随机密码

设置密码的安全等级

#降低密码的安全策略
set global validate_password_length=1;
set global validate_password_policy=0;
#这样就能设置简单的密码了,但是密码长度必须是大于等于4位
set password for 用户名@localhost = password('新密码'); 

9、授权其他客户端访问

#默认情况下其他服务器的客户端不能直接访问mysql服务端,需要对ip授权 ,'%'代表对所有远程的IP地址
#GRANT ALL PRIVILEGES ON 数据库.表名 TO 用户名@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

10、关闭本地防护墙

CentOS7使用firewalld打开关闭防火墙与端口

1、firewalld的基本使用
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld 
开机禁用  : systemctl disable firewalld
开机启用  : systemctl enable firewalld
 
 
2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

3.配置firewalld-cmd

查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息:  firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
 
那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent

centos6关闭防火墙

打开防火墙:service iptables start
关闭防火墙:service iptables stop
查看防火墙状态:service iptables status
永久开启防火墙: chkconfig iptables on
查看状态:chkconfig --list iptables
永久关闭防火墙:chkconfig iptables off
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值