Django开发个人博客网站——26、服务器centos7安装mysql

1、检查服务器版本

不同系统是要安装不同的mysql包的,因此我们首先应当查看服务器系统的版本:

uname -a 

EL is short for Red Hat Enterprise Linux (EL).
EL6 is the download for Red Hat 6.x, CentOS 6.x, and CloudLinux 6.x.
EL5 is the download for Red Hat 5.x, CentOS 5.x, CloudLinux 5.x.
EL7 is the download for Red Hat 7.x, CentOS 7.x, and CloudLinux 7.x.

如果你跟我一样安装的是centos 7的话,版本就是el7。

2、下载并安装

下载

从MySQL Yum 仓库http://dev.mysql.com/downloads/repo/yum/下载适合电脑版本的rpm包。

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

下载后执行

sudo rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

其中mysql57-community-release-el7-11.noarch.rpm是刚才下载的rpm包

安装

sudo yum install mysql-community-server

3、配置

启动mysql

sudo systemctl start mysqld.service

查看mysql服务状态

systemctl status mysqld.service

查询密码

grep 'temporary password' /var/log/mysqld.log

登录进入mysql

mysql -u root -p

输入刚才查询到的密码

修改密码
在**出填入新密码

set password for 'root'@'localhost'=password('*********');

更改编码格式
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

设置外部ip可以访问
修改/etc/my.cnf配置文件,在 [mysqld]:下面加一行

bind-address = 0.0.0.0

登录进入mysql

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'SunShuChang1#' WITH GRANT OPTION;

FLUSH PRIVILEGES;

重启mysql服务

systemctl restart mysqld.service

开启防火墙的端口设置

CentOS7的默认防火墙为firewall,且默认是不打开的。

systemctl start firewalld    #启动friewall
systemctl status firewalld 查看firewall启动情况
firewall-cmd --zone=public --add-port=3306/tcp --permanent 开启3306端口
firewall-cmd --reload  #重启防火墙
firewall-cmd --list-ports   #检查打开的端口

如果是阿里云服务器的话,还需要打开阿里云的端口才行。

最后通过navicat即可连接上!

——————————————————————————————————————————

项目的完整代码:django_blog
觉得有用的欢迎给个star。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值