阿里云cenos7安装mysql5.7

阿里云cenos7安装mysql5.7

下载mysql社区版rpm软件包(到mysql官方找到实际的下载地址)

[root@iz2zei76g05x9oeyq8ht2kz ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar

下载后解压

[root@iz2zei76g05x9oeyq8ht2kz ~]# ls
mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
[root@iz2zei76g05x9oeyq8ht2kz ~]# tar -xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-5.7.22-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-5.7.22-1.el7.x86_64.rpm
mysql-community-test-5.7.22-1.el7.x86_64.rpm
mysql-community-server-5.7.22-1.el7.x86_64.rpm
mysql-community-client-5.7.22-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.22-1.el7.x86_64.rpm
mysql-community-devel-5.7.22-1.el7.x86_64.rpm
mysql-community-common-5.7.22-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.22-1.el7.x86_64.rpm

安装(server 和 client,需要什么依赖,先安装依赖)

[root@iz2zei76g05x9oeyq8ht2kz ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	libaio.so.1()(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
	libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
	libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
	mysql-community-client(x86-64) >= 5.7.9 is needed by mysql-community-server-5.7.22-1.el7.x86_64
	mysql-community-common(x86-64) = 5.7.22-1.el7 is needed by mysql-community-server-5.7.22-1.el7.x86_64

联网yum安装 libaio,rpm安装其他的

[root@iz2zei76g05x9oeyq8ht2kz ~]# yum install libaio
[root@iz2zei76g05x9oeyq8ht2kz ~]# rpm -ivf mysql-community-libs-5.7.22-1.el7.x86_64.rpm
[root@iz2zei76g05x9oeyq8ht2kz ~]# rpm -ivf mysql-community-client-5.7.22-1.el7.x86_64.rpm 
# 还有其他需要的依赖

查看一下都安装了哪几个

[root@iz2zei76g05x9oeyq8ht2kz ~]# rpm -qa | grep -i mysql
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-server-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
mysql-community-client-5.7.22-1.el7.x86_64

启动mysql服务

[root@iz2zei76g05x9oeyq8ht2kz ~]# systemctl start mysqld.service

获取临时密码

[root@iz2zei76g05x9oeyq8ht2kz ~]# grep 'temporary password' /var/log/mysqld.log 
2018-05-22T04:21:55.960519Z 1 [Note] A temporary password is generated for root@localhost: #kTTd3i!%C_i

用临时密码登录并修改密码

[root@iz2zei76g05x9oeyq8ht2kz ~]# mysql -u root -p
Enter password: 

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';Query OK, 0 rows affected (0.00 sec)

注意:新密码要复杂点,不然不能修改成功,因为mysql5.7默认用的密码策略比较复杂,具体我忘记了,反正密码要包含大小写,数字和特殊符号。

设置开机自动启动,cenos7安装后默认是自动启动的,先查看一下(相关知识后面有)

[root@iz2zei76g05x9oeyq8ht2kz ~]# systemctl is-enabled mysqld.service
enabled

mysql开启远程访问(更改远程访问密码)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '自己设置一个密码';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

防火墙开放3306端口

注意:阿里云的服务器不用管防火墙的,因为它默认是关闭的,起到防火墙作用的是安全组,因此,需要登录阿里云到控制台到安全组添加一条策略来开放3306端口。

如果是自己的服务器,要按下面配置

[root@iz2zei76g05x9oeyq8ht2kz ~]# systemctl start iptables #启动防火墙
[root@iz2zei76g05x9oeyq8ht2kz ~]# systemctl status iptables #查看防火墙状态 

#编辑防火墙,增加端口
[root@iz2zei76g05x9oeyq8ht2kz ~]# vim /etc/sysconfig/iptables #编辑防火墙配置文件,添加下面一行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
:wq #保存退出

[root@iz2zei76g05x9oeyq8ht2kz ~]# systemctl restart iptables.service #重启防火墙使配置生效
[root@iz2zei76g05x9oeyq8ht2kz ~]# systemctl enable iptables.service #设置防火墙开机启动


测试端口是否开放

[root@iz2zei76g05x9oeyq8ht2kz ~]# wget xxx.xxx.xxx.xxx:3306

远程连接

如果无法远程连接,找原因

  1. mysql里面没有配置好,比如说授权给root外部链接。
  2. 是不是被防火墙阻止登录。
  3. 从外部访问 telnet xxx.xxx.xxx.xxx 3306端口是否能通(就是在这点上)

systemctl管理服务

service iptables restart 与 systemctl start iptables.service作用一样,service 命令实际执行的还是systemctl

  • systemctl start firewalld # 启动,
  • systemctl enable firewalld # 开机启动
  • systemctl stop firewalld # 关闭
  • systemctl disable firewalld # 取消开机启动

如何启动/关闭、启用/禁用服务?

  • 启动一个服务:systemctl start postfix.service
  • 关闭一个服务:systemctl stop postfix.service
  • 重启一个服务:systemctl restart postfix.service
  • 显示一个服务的状态:systemctl status postfix.service
  • 在开机时启用一个服务:systemctl enable postfix.service
  • 在开机时禁用一个服务:systemctl disable postfix.service
  • 查看服务是否开机启动:systemctl is-enabled postfix.service
  • 查看已启动的服务列表:systemctl list-unit-files|grep enabled
  • 查看启动失败的服务列表:systemctl --failed

PS:使用命令 systemctl is-enabled postfix.service 得到的值可以是enable、disable或static,这里的 static 它是指对应的 Unit 文件中没有定义[Install]区域,因此无法配置为开机启动服务。

说明:启用服务就是在当前“runlevel”的配置文件目录/etc/systemd/system/multi-user.target.wants/里,建立/usr/lib/systemd/system里面对应服务配置文件的软链接;禁用服务就是删除此软链接,添加服务就是添加软连接。

[root@iz2ze9nt7c47r697b3ica8z ~]# systemctl disable mysqld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/mysqld.service.
[root@iz2ze9nt7c47r697b3ica8z ~]# systemctl enable mysqld.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.

测试端口是否联通:

  1. telnet xxx.xxx.xxx.xxx 3306
  2. wget xxx.xxx.xxx.xxx:3306
  3. ssh -p 3306 username@xxx.xxx.xxx.xxx (有输出就是通)

CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall:

  • systemctl stop firewalld.service
  • systemctl disable firewalld.service
  • systemctl mask firewalld.service

2、安装iptables防火墙

  • yum install iptables-services -y

3.启动设置防火墙

  • #systemctl enable iptables
  • #systemctl start iptables

4.查看防火墙状态

  • systemctl status iptables

5编辑防火墙,增加端口

  • vi /etc/sysconfig/iptables #编辑防火墙配置文件
  • -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 80 -j ACCEPT
  • -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  • :wq! #保存退出

6.重启配置,重启系统

  • systemctl restart iptables.service #重启防火墙使配置生效
  • systemctl enable iptables.service #设置防火墙开机启动

第一次整理记录,做更好的自己,just小小爽,2018.05.55。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值