1、配置YUM源

下载mysql源安装包

[root@localhost~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

安装mysql源

[root@localhost~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm

提示【Is this ok [y/d/N]: y 输入y回车】

检查MySQL源是否安装成功

[root@localhost ~]# yum repolist enabled | grep “mysql.-community.”

2、安装MySQL

[root@localhost ~]# yum install mysql-community-server

注意:安装过程中提示【Is this ok [y/d/N]: y 输入y回车】 

出现以下表示安装成功:

Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7 Complete!

3、启动MySQL服务

[root@localhost ~]# systemctl start mysqld

查看MySQL的启动状态

[root@localhost ~]# systemctl status mysqld

4.开机启动

[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload

查看mysql下root账号的默认密码 

mysql5.7安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql。 

命令:

grep ‘temporary password’ /var/log/mysqld.log
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log
2017-10-17T08:07:03.797098Z 1 [Note] A temporary password is generated for root@localhost: 3prjY9ktM,eL
[root@localhost /]#

默认的密码是:3prjY9ktM,eL

修改配置文件 

6.1. 默认配置文件路径 

配置文件:/etc/my.cnf 

日志文件:/var/log//var/log/mysqld.log 

服务启动脚本:/usr/lib/systemd/system/mysqld.service 

socket文件:/var/run/mysqld/mysqld.pid 

6.2. 修改my.cnf文件 

6.2.1. 修改密码策略 

mysql的密码策略分为三种: 

0或LOW:Length 

1或MEDIUM:Length; numeric, lowercase/uppercase, and special characters 

2或STRONG:Length; numeric, lowercase/uppercase, and special characters; dictionary file

在my.cnf文件中增加如下设置

如果不需要密码策略,禁用密码策略
validate_password = off 密码选择策略 0-LOW,1-MEDIUM,2-STRONG需要提供密码字典文件
validate_password_policy = 0

6.2.2. 修改字符编码为utf8 

在[mysqld]下增加如下配置

character_set_server = utf8 
init_connect = ‘SET NAMES utf8’

例:

[root@localhost /]# cd /etc/
[root@localhost etc]# vi my.cnf
validate_password = off# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
validate_password = off #设置禁用密码策略 character_set_server = utf8 #修改字符编码为utf8
init_connect = 'SET NAMES utf8'
 ```
6.2.3. 保存my.cnf并重启mysql服务是配置生效 
命令:

systemctl restart mysqld


登录mysql` 命令:

mysql -uroot -p

输入密码:默认为刚才查到的密码”3prjY9ktM,eL”

``

[root@localhost etc]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.20

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

修改密码

命令:ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678'; 
或命令:set password for 'root'@'localhost'=password('12345678');

说明:

  1. 如果之前没有设置密码策略,则密码12345678则不会通过验证,密码修改会失败
 grant all privileges on *.* to 'root'@'0.0.0.0'identified by '123456' with grant option;

密码修改不成功时则部分功能也无法使用,例如查看密码策略

 show variables like ‘%password%’;

查看密码策略 

命令:show variables like '%password%'; 

此处为 validate_password = off 设置后的结果

查看字符编码 

命令:show variables like '%character%';

添加远程账户 

命令:

grant all privileges on *.* to 'root'@'%'identified by '123456' with grant option;

命令:FLUSH PRIVILEGES; 使设置生效

如果你想允许用户myuser从ip为0.0.0.0所有的主机连接到mysql服务器,并使用mypassword作为密码

刷新权限

FLUSH PRIVILEGES;

至此,可以远程连接并操作数据库啦!

CentOS服务器安装mysql的更多相关文章

  1. Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)

    Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建) 具体案例:局域网内有两台主机,一台Linux.一台Windows,现在需要配置一台Cacti监控服务器对这两台 ...

  2. CentOS 下 MySQL DateBasic 抢救

    CentOS 下 MySQL DateBasic 抢救 强 Kill 数据库进程. 分析问题:确定报错内容 报错信息:The server quit without updating PID file ...

  3. centos安装 mysql

    centos安装 mysql 1. 下载mysqlmysql被oracle收购后现在退出了企业版和社区版本,社区版本是开源的,企业版是收费的.社区版可以下载源码也可以下载二进制文件包.源码安装比较麻烦 ...

  4. centOS安装Mysql指南

    centOS安装Mysql指南 说明:使用操作系统centOS6.4 32位系统:mysql:mysql-5.7.10-linux-glibc2.5-i686.tar.gz; 一.准备 下载mysql ...

  5. windows下的mysql客户端mysqlworkbench链接虚拟机上CentOS的mysql服务器

    本人在虚拟机上CentOS的Linux环境下安装了mysql服务器,在本地Windows下安装了mysql的客户端mysqlworkbench ,所以就想让windows下的mysql客户端mysql ...

  6. 【Linux】Centos部署MySQL

    将CentOS部署MySQL需要本地配置环境.本地编译MySQL,耗时较长的情况,优化为编译成型MySQL并打包,推送并按配置部署. 首先需要在一台机器配置好环境,搭个YUM源,并将所需要的包取出备用 ...

  7. Centos系统mysql 忘记root用户的密码

    Centos系统mysql 忘记root用户的密码: 第一步:(停掉正在运行的mysql) [root@maomao ~]# /etc/init.d/mysqld stop Stopping MySQ ...

  8. CentOS下MySQL 5.7编译安装

    CentOS下MySQL 5.7编译安装   文章目录 安装依赖包 下载相应源码包 添加mysql用户 预编译 编译安装 启动脚本,设置开机自启动 /etc/my.cnf,仅供参考 初始化数据库 设置 ...

  9. CentOS安装MySQL问题汇总

    遇到的错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) denied for ...

随机推荐

  1. oracle-ORA-01567错误

    删除日志4时将在线索1中保留少于两个日志文件

  2. codevs1839 洞穴勘测

    题目描述 Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道 ...

  3. phpcms url路由规则、多站点、PC手机切换

    解决一个分站点pc手机共存的问题 首先需要有PC手机两套模板.通过修改url路由规则,在同一目录下生成PC手机两套静态网站,PC使用默认url路由规则,手机端使用文件名追加“_m”的路由规则. 然后通 ...

  4. linux下安装composer以及使用composer安装laravel

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/nianzhi1202/article/details/72770099 一.安装composer之前 ...

  5. 计算php程序运行时间

    <?php   //程序运行时间 $starttime = explode(' ',microtime()); echo microtime(); /*········以下是代码区······· ...

  6. Unity3D游戏开发之在Unity3D中视频播放功能的实现

    版权声明:欢迎订阅公众号[5厘米的理想],愿生命里的每个小理想,都能成为生命里的小确幸.本文地址为: https://blog.csdn.net/qinyuanpei/article/details/ ...

  7. oracle函数 NLS_INITCAP(x[,y])

    [功能]返回字符串并将字符串的第一个字母变为大写,其它字母小写; [参数]x字符型表达式 [参数]Nls_param可选, 查询数据级的NLS设置:select * from nls_database ...

  8. Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法

    今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数def liebiao(): for x in range(10): yield x#函数调 ...

  9. 2018-8-10-WPF-如何在绑定失败异常

    title author date CreateTime categories WPF 如何在绑定失败异常 lindexi 2018-08-10 19:16:53 +0800 2018-05-17 1 ...

  10. 虎牙在全球 DNS 秒级生效上的实践

    本文整理自虎牙中间件团队在 Nacos Meetup 的现场分享,阿里巴巴中间件受权发布. 这次分享的是全球 DNS 秒级生效在虎牙的实践,以及由此产生的一些思考,整体上,分为以下5各部分: 背景介绍 ...