从 CentOS 7 系统开始,MariaDB 成为 yum 源中默认的数据库安装包。在 CentOS 7 及以上的系统中使用 yum 安装 MySQL 包将无法使用 MySQL。您可以选择使用完全兼容的 MariaDB,或依照本文介绍配置来继续使用 MySQL。本文以在 CentOS 7 下安装 MySQL 5.7.21 为例。

1. 检查 MariaDB 是否安装

yum list installed | grep mariadb

2. 卸载全部 MariaDB 相关

yum -y remove mariadb*

3. 下载 MySQL 的 YUM 源
进入到要下载到的路径:cd /usr/local/src

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

4. 安装 MySQL 的 YUM 源
 rpm -ivh mysql57-community-release-el7-11.noarch.rpm

5. 检查 MySQL 的 YUM 源是否安装成功
 yum repolist enabled | grep "mysql.*-community.*"

如图所示则安装成功。

6. 查看 MySQL 版本

yum repolist all | grep mysql

7. 安装 MySQL
yum install mysql-community-server

一直输 y 就可以了。

8. 启动 MySQL 服务
systemctl start mysqld

9. 测试连接 MySQL 服务
mysql -u root 或者 mysql

--------------------------------------------------------------------------------

提示:

刚安装的 MySQL 是没有密码的,这时如果出现:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO),解决如下:

① 停止 MySQL 服务:systemctl stop mysqld

② 以不检查权限的方式启动 MySQL: mysqld --user=root --skip-grant-tables &

③ 再次输入 mysql -u root 或者 mysql,这次就可以进来了。

④ 更新密码:

MySQL 5.7 以下版本:UPDATE mysql.user SET Password=PASSWORD('123456') where USER='root';

MySQL 5.7 版本:UPDATE mysql.user SET authentication_string=PASSWORD('123456') where USER='root';

⑤ 刷新:flush privileges;

⑥ 退出:exit;

设置完之后,输入 mysql -u root -p,这时输入刚设置的密码,就可以登进数据库了。

远程访问 MySQL,需要开放 3306 端口:

firewall-cmd --permanent --zone=public --add-port=3306/tcp

firewall-cmd --permanent --zone=public --add-port=3306/udp

firewall-cmd --reload

如果是 CentOS 7,需要将 MySQL 服务加入防火墙,然后重启防火墙:

firewall-cmd --zone=public --permanent --add-service=mysql

systemctl restart firewalld

--------------------------------------------------------------------------------

提示:

在输入 firewall-cmd --permanent --zone=public --add-port=3306/tcp 时可能会报 'FirewallD is not running',是说防火墙本身就没有打开,解决方法:

① 查看防火墙状态:systemctl status firewalld,会发现状态是 dead,即防火墙未开启。

② 打开防火墙:systemctl start firewalld

③ 再次查看防火墙状态:systemctl status firewalld,这时会发现状态变为 running,即防火墙开启成功。
这时再输入开放 3306 端口的命令就没有问题了。

11. 设置允许远程访问
默认情况下 MySQL 是不允许远程连接的,所以在 Java 项目或者 MySQLWorkbench 等数据库连接工具连接服务器上的 MySQL 服务的时候会报 "Host 'x.x.x.x' is not allowed to connect to this MySQL server"。可以通过下面的设置解决。详细可以参考之前写的一篇文章XXX is not allowed to connect to this MySQL server。 ① grant all privileges on *.* to root@"%" identified by '0'; ② flush privileges; -------------------------------------------------------------------------------- 提示: 在执行第一条命令的时候,可能会报: 'ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.' 需要让我们重置密码。原因是因为我刚刚的命令中设置的数据库密码是0,这个密码过于简单,不符合 MySQL 的安全要求。只要重新设置一个复杂点的密码就可以了: mysql> SET PASSWORD = PASSWORD('xxx');   //xxx 是重置的新的复杂的密码 -------------------------------------------------------------------------------- 思考: 之前设置简单密码是没有问题的,可能原因: ① 可能目前环境是 CentOS 7 + MySQL 5.7.21,安全性有所提升。 ② 也有可能是之前的数据库设置过 mysql> set global validate_password_policy=0; mysql> set global validate_password_length=1; 允许设置简单密码。

  

12. 相关命令
MySQL 相关: systemctl start mysqld    #启动mysql systemctl stop mysqld    #停止mysqld systemctl restart mysqld    #重启mysqld systemctl enable mysqld    #设置开机启动 systemctl status mysqld    #查看 MySQL Server 状态 防火墙相关: systemctl status firewalld    #查看防火墙状态 systemctl start firewalld    #打开防火墙 systemctl stop firewalld    #关闭防火墙 systemctl restart firewalld    #重启防火墙

  

CentOS 7 下安装 MySQL 5.7的更多相关文章

  1. CentOS 7 下安装 MySQL 8.x

    CentOS 7 下安装 MySQL 8.x 作者:Grey 原文地址: 博客园:CentOS 7 下安装 MySQL 8.x CSDN:CentOS 7 下安装 MySQL 8.x 环境 CentO ...

  2. CentOS 7 下安装 MySQL 8.0

    前言 本篇文章主要介绍在 CentOS 7 环境下安装 MySQL 8.0. 正文 1. 配置yum源 首先在 https://dev.mysql.com/downloads/repo/yum/ 找到 ...

  3. Centos 7 下安装mysql

    // 卸载原有maridb-lib库 [root@localhost ~]# rpm -qa | grep mariadb mariadb-libs-5.5.41-2.el7_0.x86_64 [ro ...

  4. CentOS 7 下安装 mysql ,以及用到的命令

    VMware虚拟机装好后,再装个CentOS7系统,以上环境自行百度... 一.Linux下查看mysql是否安装 1.指令ps -ef|grep mysql [root@localhost 桌面]# ...

  5. CentOS 7下安装Mysql 5.7

    参见http://www.07net01.com/2016/03/1355735.html 过程中需要安装perl CentOS 7 采用了 firewalld 防火墙 service firewal ...

  6. centos 7下安装mysql

    可参考: http://blog.csdn.net/xyang81/article/details/51759200 1.去mysql官方网站查询最新的版本: 2.运行指令: wget http:// ...

  7. centos 6.5下安装mysql+nginx+redmine 3.1.0 笔记

    centos 6.5下安装mysql+nginx+redmine 3.1.0 笔记 目录[-] 过程 1.安装RVM 2.利用rvm安装 Ruby 1.9.3 并设为默认 3.安装rails 4.安装 ...

  8. Centos下安装mysql 总结

    一.MySQL安装 Centos下安装mysql 请点开:http://www.centoscn.com/CentosServer/sql/2013/0817/1285.html 二.MySQL的几个 ...

  9. CentOS 7 下安装 LEMP 服务(nginx、MariaDB/MySQL 和 php)

    原文 CentOS 7 下安装 LEMP 服务(nginx.MariaDB/MySQL 和 php) LEMP 组合包是一款日益流行的网站服务组合软件包,在许多生产环境中的核心网站服务上起着强有力的作 ...

随机推荐

  1. js off 缓动动画

    动画也有很多种,一起来学习,缓动动画吧 缓动动画 1.缓动动画原理=盒子位置+(目标盒子位置-现在盒子位置)/10 2.步长越来越小 3.让步长越来越小的公式      步长=(目标位置-本身位置)/ ...

  2. SweetAlert 2 全网最详细的使用方法

    官网链接 SweetAlert2 官网链接 准备阶段 CDN js 如果该 链接 时间久远了 , 可以在官网去找找最新的 可以把 js 复制出来 自己新建一个文件 然后 引用到 html 中 1. 带 ...

  3. 【随记】安装SQL Server 2008 R2 提示创建usersettings/microsoft.sqlserver.configuration.landingpage.properties.se

    在安装SQL Server 2008 R2 提示创建usersettings/microsoft.sqlserver.configuration.landingpage.properties.se.. ...

  4. Linux 搜索查找类指令

    一.find  指令 find 指令将从指定目录向下递归遍历其各子目录,将满足条件的文件或者目录显示在终端. 基本语法 find  [搜索范围]  [选项] 选项说明 -name            ...

  5. 【JVM】虚拟机字节码执行引擎

    概念模型上,典型的帧栈结构如下(栈是线程私有的,也就是每个线程都会有自己的栈).                     典型的帧栈结构 局部变量表 存放方法参数和方法内部定义的局部变量.在编译阶段, ...

  6. [转] Filezilla server设置指南及中文乱码、登录欢迎语问题解决

    一.filezilla server 安装指南:FileZilla是一款免费而且开源的FTP工具.包括FileZilla Client,FileZilla Server两个版本.FileZilla S ...

  7. nice -n 10 bash 和 chrt 10 bash 和 echo -17 > /proc/PID/oom_score_adj

    进程优先级起作用的方式从发明以来基本没有什么变化,无论是只有一个cpu的时代,还是多核cpu时代,都是通过控制进程占用cpu时间的长短来实现的. 就是说在同一个调度周期中,优先级高的进程占用的时间长些 ...

  8. axios请求数据完整

    <template> <!-- 所有的内容要被根节点包含起来 --> <div id="home"> 首页组件 <button @clic ...

  9. matplotlib常用操作2

    关于matplotlib学习还是强烈建议常去官方http://matplotlib.org/contents.html里查一查各种用法和toturial等. 下面是jupyter notebook代码 ...

  10. idea-debug启动会卡住不动,BeanPostProcessors (for example: not eligible for auto-proxying),报错解决

    debug启动会卡住不动,run模式启动正常 debug启动输出到下面这行之后,就不会继续输出了 爆出各种 [INFO]- Bean 'dataSource' of type [class Druid ...