linux系统下的mysql的安装(centos7+mysql5.6)

Mysql安装

步骤:

1.CentOS自带的mysql

           输入 rpm -qa | grep mysql

2.将自带的mysql卸载

           输入rpm -e --nodeps  加上上面查询的版本号

3.安装前,需要卸载自带的mariadb的sql版本

        输入rpm -qa|grep -i mariadb-libs  (查找系统中的版本)

       输入rpm -e 上面命令查询的版本  --nodeps

4.使用ssh工具将压缩包上传至linux系统下的文件夹中  /usr/local/mysql

          使用以下命令将文件解压到当前文件夹中

tar  -xvf  压缩包名

5.安装系统中所需依赖(选做,可以根据报错网上查找依赖命令)

yum install glibc.i686

yum install libstdc++.x86_64

yum install libstdc++.i686

yum install libaio.so.1

yum -y install libaio.so.1 libgcc_s.so.1 libstdc++.so.6

yum  update libstdc++-4.4.7-4.el6.x86_64

以上命令全部使用Y,如果后两个命令报错。不管他。

6.在/usr/local/mysql下安装mysql

安装服务器端:rpm -ivh MySQL-server-5.6.22-1.el6.i686.rpm

安装客户端:rpm -ivh MySQL-client-5.6.22-1.el6.i686.rpm

7.启动mysql

service mysql start

注意:启动报错。显示 The server quit without updating PID file

解决办法:管理员权限下使用db -h 查看磁盘使用情况,过小则扩充虚拟机磁盘空间;然后

查看mysql进程:ps -ef |grep mysql ;如果有许多mysql进程在启动,则使用命令杀死进程:kill -9   进程号;

因为mysql启动过多,导致mysql进程坏死。(类似于window系统中,开启了过多程序。导致卡死状态)

8.将mysql加到系统服务中并设置开机启动

加入到系统服务:chkconfig --add mysql
自动启动:chkconfig mysql on

9.登录mysql

mysql安装好后会生成一个临时随机密码,存储位置在/root/.mysql_secret

注意:因为该文件是隐藏文件,直接使用cat查找命令。将铭文随机密码复制登录(与windows不同的是mysql密码不是自带root)

然后通过   msyql –u root -p  密码   命令登录linux系统下的mysql数据库

此间,可以通过输入set password = password('root'); 修改数据库密码!

10.实现远程连接(在局域网中连接)

在登录mysql命令行中输入以下命令,开启可以远程登录

grant all privileges on *.* to 'root' @'%' identified by 'root';
flush privileges;

11.在远程登录之前可能需要关闭防火墙(不需要考虑安全)或者开放3306端口(考虑安全但是麻烦)

CentOS7默认的防火墙不是iptables,而是firewalle.

安装iptable iptable-service

#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables
yum update iptables 
#安装iptables-services
yum install iptables-services

禁用/停止自带的firewalld服务

#停止firewalld服务
systemctl stop firewalld
#禁用firewalld服务
systemctl mask firewalld

不安全做法

直接执行:service iptables stop

安全做法

执行:

iptables -A INPUT -p tcp --dport  3306 -j ACCEPT

service iptables save

service iptables start

以下为长见识项

设置相关防火墙规则

设置现有规则(规则转载自https://www.cnblogs.com/kreo/p/4368811.html?tdsourcetag=s_pcqq_aiomsg)

#查看iptables现有规则
iptables -L -n
#先允许所有,不然有可能会杯具
iptables -P INPUT ACCEPT
#清空所有默认规则
iptables -F
#清空所有自定义规则
iptables -X
#所有计数器归0
iptables -Z
#允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -i lo -j ACCEPT
#开放22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#开放21端口(FTP)
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#开放80端口(HTTP)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#开放443端口(HTTPS)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
#允许ping
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
#允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT
#其他入站一律丢弃
iptables -P INPUT DROP
#所有出站一律绿灯
iptables -P OUTPUT ACCEPT
#所有转发一律丢弃
iptables -P FORWARD DROP

其他规则设定

#如果要添加内网ip信任(接受其所有TCP请求)
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
#过滤所有非以上规则的请求
iptables -P INPUT DROP
#要封停一个IP,使用下面这条命令:
iptables -I INPUT -s ***.***.***.*** -j DROP
#要解封一个IP,使用下面这条命令:
iptables -D INPUT -s ***.***.***.*** -j DROP

保存规则设定

service iptables save

开启iptables服务 

#注册iptables服务
#相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service

 

你可能感兴趣的:(linux)