侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

CentOS 7.4 64位安装配置MySQL8.0的详细步骤

linux  /  管理员 发布于 7年前   144

第一步:获取mysql YUM源

进入mysql官网获取RPM包下载地址

https://dev.mysql.com/downloads/repo/yum/

点击下载

获取到下载链接:

https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

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

第二步:下载和安装mysql源

•进入mysql文件夹,没有的自行创建

[root@VM_0_10_centos /]# cd /usr/local/mysql/[root@VM_0_10_centos mysql]#

•下载源安装包

[root@VM_0_10_centos mysql]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm--2018-08-04 10:29:39-- https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpmResolving repo.mysql.com (repo.mysql.com)... 23.219.33.198Connecting to repo.mysql.com (repo.mysql.com)|23.219.33.198|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 25820 (25K) [application/x-redhat-package-manager]Saving to: ‘mysql80-community-release-el7-1.noarch.rpm'100%[==========================================================================>] 25,820 112KB/s in 0.2s 2018-08-04 10:29:40 (112 KB/s) - ‘mysql80-community-release-el7-1.noarch.rpm' saved [25820/25820][root@VM_0_10_centos mysql]# lltotal 28-rw-r--r-- 1 root root 25820 Apr 18 13:24 mysql80-community-release-el7-1.noarch.rpm[root@VM_0_10_centos mysql]#

•安装mysql源

[root@VM_0_10_centos mysql]# yum -y localinstall mysql80-community-release-el7-1.noarch.rpm

第三步:在线安装MySQL

[root@VM_0_10_centos mysql]# yum -y install mysql-community-server

下载东西比较多,等几分钟。

第四步:启动Mysql服务

[root@VM_0_10_centos mysql]# systemctl start mysqld

第五步:设置开机启动

[root@VM_0_10_centos mysql]# systemctl enable mysqld[root@VM_0_10_centos mysql]# systemctl daemon-reload

第六步:修改root本地登录密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。用grep命令搜一下

[root@VM_0_10_centos mysql]# grep "A temporary password is generated for root@localhost" /var/log/mysqld.log 2018-08-02T02:19:55.829527Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: !J:KUwU9y0ZR2018-08-02T04:49:34.979689Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pw</s9,Wivm22018-08-04T02:40:46.781768Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: nNyK,Y)Wd0-G[root@VM_0_10_centos mysql]#

这里有三条搜索结果,因为我重复装了3次MySQL,如果第一次安装是只会有一条的。

 直接拿到临时默认密码 : nNyK,Y)Wd0-G

•登录MySQL

[root@VM_0_10_centos mysql]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.12Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

•更改root账户临时密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]';Query OK, 0 rows affected (0.03 sec)mysql>

[email protected] 请替换成你自己的密码。

(备注 mysql8.0默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位)

第七步:创建新用户、授权、远程登录(不要直接使用root账户登录)

•创建easyoh-mp用户并且授权远程登录

mysql> CREATE USER 'easyoh-mp'@'%' IDENTIFIED BY '[email protected]';Query OK, 0 rows affected (0.04 sec)mysql> GRANT ALL ON *.* TO 'easyoh-mp'@'%';Query OK, 0 rows affected (0.03 sec)mysql>

•在sqlyog客户端用easyoh-mp账户登录(其他客户端也可以,随意)

发现会报plugin caching_sha2_password错误。这是因为MySQL8.0密码策略默认为caching_sha2_password。与5.7有所不同。

•进入MySQL数据库查询user表信息

mysql> use mysql;Database changedmysql> select user,host,plugin from user;+------------------+-----------+-----------------------+| user  | host | plugin  |+------------------+-----------+-----------------------+| easyoh-mp | %  | caching_sha2_password || mysql.infoschema | localhost | caching_sha2_password || mysql.session | localhost | caching_sha2_password || mysql.sys | localhost | caching_sha2_password || root  | localhost | caching_sha2_password |+------------------+-----------+-----------------------+5 rows in set (0.00 sec)mysql>

发现确实是caching_sha2_password

•依次执行下面语句

mysql> ALTER USER 'easyoh-mp'@'%' IDENTIFIED BY '[email protected]' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.04 sec)mysql> ALTER USER 'easyoh-mp'@'%' IDENTIFIED WITH mysql_native_password BY '[email protected]'; Query OK, 0 rows affected (0.05 sec)mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec)mysql>

再次登录就可以登录成功了。

第8步:编码

mysql> show variables like '%character%';+--------------------------+--------------------------------+| Variable_name  | Value    |+--------------------------+--------------------------------+| character_set_client | utf8mb4   || character_set_connection | utf8mb4   || character_set_database | utf8mb4   || character_set_filesystem | binary    || character_set_results | utf8mb4   || character_set_server | utf8mb4   || character_set_system | utf8    || character_sets_dir | /usr/share/mysql-8.0/charsets/ |+--------------------------+--------------------------------+8 rows in set (0.01 sec)mysql>

MySQL8.0默认就是utf8mb4编码,无需更改。

OK 至此 Mysql安装配置完毕;

全流程操作记录

[root@VM_0_10_centos ~]# [root@VM_0_10_centos /]# cd /usr/local/mysql/[root@VM_0_10_centos mysql]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm--2018-08-04 10:29:39-- https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpmResolving repo.mysql.com (repo.mysql.com)... 23.219.33.198Connecting to repo.mysql.com (repo.mysql.com)|23.219.33.198|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 25820 (25K) [application/x-redhat-package-manager]Saving to: ‘mysql80-community-release-el7-1.noarch.rpm'100%[==========================================================================>] 25,820 112KB/s in 0.2s 2018-08-04 10:29:40 (112 KB/s) - ‘mysql80-community-release-el7-1.noarch.rpm' saved [25820/25820][root@VM_0_10_centos mysql]# lltotal 28-rw-r--r-- 1 root root 25820 Apr 18 13:24 mysql80-community-release-el7-1.noarch.rpm[root@VM_0_10_centos mysql]# yum -y localinstall mysql80-community-release-el7-1.noarch.rpm Loaded plugins: fastestmirror, langpacksExamining mysql80-community-release-el7-1.noarch.rpm: mysql80-community-release-el7-1.noarchMarking mysql80-community-release-el7-1.noarch.rpm to be installedResolving Dependencies--> Running transaction check---> Package mysql80-community-release.noarch 0:el7-1 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================================================================================================================================================= Package       Arch     Version    Repository        Size=================================================================================================================================================================================================================Installing: mysql80-community-release    noarch    el7-1     /mysql80-community-release-el7-1.noarch    31 kTransaction Summary=================================================================================================================================================================================================================Install 1 PackageTotal size: 31 kInstalled size: 31 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transactionWarning: RPMDB altered outside of yum. Installing : mysql80-community-release-el7-1.noarch       1/1  Verifying : mysql80-community-release-el7-1.noarch       1/1 Installed: mysql80-community-release.noarch 0:el7-1         Complete![root@VM_0_10_centos mysql]# yum -y install mysql-community-serverLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileepel 12641/12641Resolving Dependencies--> Running transaction check---> Package mysql-community-server.x86_64 0:8.0.12-1.el7 will be installed--> Processing Dependency: mysql-community-common(x86-64) = 8.0.12-1.el7 for package: mysql-community-server-8.0.12-1.el7.x86_64--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.0 for package: mysql-community-server-8.0.12-1.el7.x86_64--> Running transaction check---> Package mysql-community-client.x86_64 0:8.0.12-1.el7 will be installed--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.0 for package: mysql-community-client-8.0.12-1.el7.x86_64---> Package mysql-community-common.x86_64 0:8.0.12-1.el7 will be installed--> Running transaction check---> Package mysql-community-libs.x86_64 0:8.0.12-1.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================================================================================================================================================= Package       Arch     Version      Repository      Size=================================================================================================================================================================================================================Installing: mysql-community-server     x86_64     8.0.12-1.el7     mysql80-community     349 MInstalling for dependencies: mysql-community-client     x86_64     8.0.12-1.el7     mysql80-community     26 M mysql-community-common     x86_64     8.0.12-1.el7     mysql80-community     541 k mysql-community-libs     x86_64     8.0.12-1.el7     mysql80-community     2.2 MTransaction Summary=================================================================================================================================================================================================================Install 1 Package (+3 Dependent packages)Total download size: 377 MInstalled size: 1.7 GDownloading packages:(1/4): mysql-community-common-8.0.12-1.el7.x86_64.rpm     | 541 kB 00:00:05 (2/4): mysql-community-client-8.0.12-1.el7.x86_64.rpm     | 26 MB 00:00:12 (3/4): mysql-community-server-8.0.12-1.el7.x86_64.rpm     | 349 MB 00:02:26 (4/4): mysql-community-libs-8.0.12-1.el7.x86_64.rpm     | 2.2 MB 00:03:37 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total          1.7 MB/s | 377 MB 00:03:43 Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : mysql-community-common-8.0.12-1.el7.x86_64       1/4  Installing : mysql-community-libs-8.0.12-1.el7.x86_64       2/4  Installing : mysql-community-client-8.0.12-1.el7.x86_64       3/4  Installing : mysql-community-server-8.0.12-1.el7.x86_64       4/4  Verifying : mysql-community-common-8.0.12-1.el7.x86_64       1/4  Verifying : mysql-community-libs-8.0.12-1.el7.x86_64       2/4  Verifying : mysql-community-client-8.0.12-1.el7.x86_64       3/4  Verifying : mysql-community-server-8.0.12-1.el7.x86_64       4/4 Installed: mysql-community-server.x86_64 0:8.0.12-1.el7         Dependency Installed: mysql-community-client.x86_64 0:8.0.12-1.el7    mysql-community-common.x86_64 0:8.0.12-1.el7    mysql-community-libs.x86_64 0:8.0.12-1.el7    Complete![root@VM_0_10_centos mysql]# systemctl start mysqld[root@VM_0_10_centos mysql]# systemctl enable mysqld[root@VM_0_10_centos mysql]# systemctl daemon-reload[root@VM_0_10_centos mysql]# grep "A temporary password is generated for root@localhost" /var/log/mysqld.log 2018-08-02T02:19:55.829527Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: !J:KUwU9y0ZR2018-08-02T04:49:34.979689Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pw</s9,Wivm22018-08-04T02:40:46.781768Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: nNyK,Y)Wd0-G[root@VM_0_10_centos mysql]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.12Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]';Query OK, 0 rows affected (0.03 sec)mysql> CREATE USER 'easyoh-mp'@'%' IDENTIFIED BY '[email protected]';Query OK, 0 rows affected (0.04 sec)mysql> GRANT ALL ON *.* TO 'easyoh-mp'@'%';Query OK, 0 rows affected (0.03 sec)mysql> use mysql;Database changedmysql> select user,host,plugin from user;+------------------+-----------+-----------------------+| user  | host | plugin  |+------------------+-----------+-----------------------+| easyoh-mp | %  | caching_sha2_password || mysql.infoschema | localhost | caching_sha2_password || mysql.session | localhost | caching_sha2_password || mysql.sys | localhost | caching_sha2_password || root  | localhost | caching_sha2_password |+------------------+-----------+-----------------------+5 rows in set (0.00 sec)mysql> ALTER USER 'easyoh-mp'@'%' IDENTIFIED BY '[email protected]' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.04 sec)mysql> ALTER USER 'easyoh-mp'@'%' IDENTIFIED WITH mysql_native_password BY '[email protected]'; Query OK, 0 rows affected (0.05 sec)mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec)mysql> show variables like '%character%';+--------------------------+--------------------------------+| Variable_name  | Value    |+--------------------------+--------------------------------+| character_set_client | utf8mb4   || character_set_connection | utf8mb4   || character_set_database | utf8mb4   || character_set_filesystem | binary    || character_set_results | utf8mb4   || character_set_server | utf8mb4   || character_set_system | utf8    || character_sets_dir | /usr/share/mysql-8.0/charsets/ |+--------------------------+--------------------------------+8 rows in set (0.01 sec)

 这里有个问题,新密码设置的时候如果设置的过于简单会报错:

  原因是因为MySQL有密码设置的规范,具体是与validate_password_policy的值有关:

  MySQL完整的初始密码规则可以通过如下命令查看:

mysql> SHOW VARIABLES LIKE 'validate_password%';+--------------------------------------+-------+| Variable_name   | Value |+--------------------------------------+-------+| validate_password_check_user_name | OFF || validate_password_dictionary_file | || validate_password_length  | 4 || validate_password_mixed_case_count | 1 || validate_password_number_count | 1 || validate_password_policy  | LOW || validate_password_special_char_count | 1 |+--------------------------------------+-------+7 rows in set (0.01 sec)

  密码的长度是由validate_password_length决定的,而validate_password_length的计算公式是:

validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)

我的是已经修改过的,初始情况下第一个的值是ON,validate_password_length是8。可以通过如下命令修改:

mysql> set global validate_password_policy=0;mysql> set global validate_password_length=1;

总结

以上所述是小编给大家介绍的CentOS 7.4 64位安装配置MySQL8.0的详细步骤,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!


  • 上一条:
    CentOS 7中升级MySQL 5.7.23的坑与解决方法
    下一条:
    初探Linux的系统日志
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客