阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7.4 64位安装配置MySQL8.0

435次阅读
没有评论

共计 15870 个字符,预计需要花费 40 分钟才能阅读完成。

第一步:获取 MySQL YUM 源

进入 mysql 官网获取 RPM 包下载地址
https://dev.mysql.com/downloads/repo/yum/

CentOS 7.4 64 位安装配置 MySQL8.0

点击下载

CentOS 7.4 64 位安装配置 MySQL8.0

获取到下载链接:
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.rpm
Resolving repo.mysql.com (repo.mysql.com)… 23.219.33.198
Connecting to repo.mysql.com (repo.mysql.com)|23.219.33.198|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 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]# ll
total 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:KUwU9y0ZR
2018-08-02T04:49:34.979689Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pw</s9,Wivm2
2018-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 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12

Copyright (c) 2000, 2018, 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>

•更改 root 账户临时密码
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘linuxidc@linuxidc.com’;
Query OK, 0 rows affected (0.03 sec)

mysql>

linuxidc@linuxidc.com 请替换成你自己的密码。
(备注 mysql8.0 默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少 8 位)

第七步:创建新用户、授权、远程登录(不要直接使用 root 账户登录)
•创建 linuxidc-mp 用户并且授权远程登录
mysql> CREATE USER ‘linuxidc-mp’@’%’ IDENTIFIED BY ‘linuxidc@linuxidc.com’;
Query OK, 0 rows affected (0.04 sec)

mysql> GRANT ALL ON *.* TO ‘linuxidc-mp’@’%’;
Query OK, 0 rows affected (0.03 sec)

mysql>

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

CentOS 7.4 64 位安装配置 MySQL8.0

发现会报 plugin caching_sha2_password 错误。这是因为 MySQL8.0 密码策略默认为 caching_sha2_password。与 5.7 有所不同。
•进入 MySQL 数据库查询 user 表信息
mysql> use mysql;
Database changed
mysql> select user,host,plugin from user;
+——————+———–+———————–+
| user            | host      | plugin                |
+——————+———–+———————–+
| linuxidc-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 ‘linuxidc-mp’@’%’ IDENTIFIED BY ‘linuxidc@linuxidc.com’ PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.04 sec)

mysql> ALTER USER ‘linuxidc-mp’@’%’ IDENTIFIED WITH mysql_native_password BY ‘linuxidc@linuxidc.com’;
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.rpm
Resolving repo.mysql.com (repo.mysql.com)… 23.219.33.198
Connecting to repo.mysql.com (repo.mysql.com)|23.219.33.198|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 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]# ll
total 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, langpacks
Examining mysql80-community-release-el7-1.noarch.rpm: mysql80-community-release-el7-1.noarch
Marking mysql80-community-release-el7-1.noarch.rpm to be installed
Resolving Dependencies
–> Running transaction check
—> Package mysql80-community-release.noarch 0:el7-1 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================================================
 Package                                                Arch                                Version                                Repository                                                            Size
=================================================================================================================================================================================================================
Installing:
 mysql80-community-release                              noarch                              el7-1                                  /mysql80-community-release-el7-1.noarch                                31 k

Transaction Summary
=================================================================================================================================================================================================================
Install  1 Package

Total size: 31 k
Installed size: 31 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: 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-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel                                                                                                                                                                                                12641/12641
Resolving 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 Resolution

Dependencies Resolved

=================================================================================================================================================================================================================
 Package                                                  Arch                                      Version                                          Repository                                            Size
=================================================================================================================================================================================================================
Installing:
 mysql-community-server                                    x86_64                                    8.0.12-1.el7                                    mysql80-community                                    349 M
Installing 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 M

Transaction Summary
=================================================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 377 M
Installed size: 1.7 G
Downloading 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 check
Running transaction test
Transaction test succeeded
Running 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:KUwU9y0ZR
2018-08-02T04:49:34.979689Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pw</s9,Wivm2
2018-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 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12

Copyright (c) 2000, 2018, 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 ‘linuxidc@linuxidc.com’;
Query OK, 0 rows affected (0.03 sec)

mysql> CREATE USER ‘linuxidc-mp’@’%’ IDENTIFIED BY ‘linuxidc@linuxidc.com’;
Query OK, 0 rows affected (0.04 sec)

mysql> GRANT ALL ON *.* TO ‘linuxidc-mp’@’%’;
Query OK, 0 rows affected (0.03 sec)

mysql> use mysql;
Database changed
mysql> select user,host,plugin from user;
+——————+———–+———————–+
| user            | host      | plugin                |
+——————+———–+———————–+
| linuxidc-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 ‘linuxidc-mp’@’%’ IDENTIFIED BY ‘linuxidc@linuxidc.com’ PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.04 sec)

mysql> ALTER USER ‘linuxidc-mp’@’%’ IDENTIFIED WITH mysql_native_password BY ‘linuxidc@linuxidc.com’;
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;

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计15870字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19348
评论数
4
阅读量
7805466
文章搜索
热门文章
开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南 大家好,我是星哥。之前介绍了腾讯云的 Code...
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板 1Panel:小白轻松构建 Web 服务与面板加固指南 哈喽,我是星哥,经常有人问我不...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
星哥带你玩飞牛NAS-13:自动追番、订阅下载 + 刮削,动漫党彻底解放双手!

星哥带你玩飞牛NAS-13:自动追番、订阅下载 + 刮削,动漫党彻底解放双手!

星哥带你玩飞牛 NAS-13:自动追番、订阅下载 + 刮削,动漫党彻底解放双手! 作为动漫爱好者,你是否还在为...
支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare 也瘫了连监控都挂,根因藏在哪? 最近两天的互联网堪称“故障...
终于收到了以女儿为原型打印的3D玩偶了

终于收到了以女儿为原型打印的3D玩偶了

终于收到了以女儿为原型打印的 3D 玩偶了 前些日子参加某网站活动,获得一次实物 3D 打印的机会,于是从众多...
自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个 AI 智能体 — 跟创业大佬对话 前言 智能体(Agent)已经成为创业者和技术人绕...
星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛 NAS 硬件 03:五盘位 +N5105+ 双网口的成品 NAS 值得入手吗 前言 大家好,我...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你 为什么要用宝塔跑分? 宝塔跑分其实就是对 CPU、内存、磁盘、IO 做...
如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的 Nano Banana Pro?附赠邪修的用法 前言 大家好,我是星哥,今天来介绍谷歌的 ...
150元打造低成本NAS小钢炮,捡一块3865U工控板

150元打造低成本NAS小钢炮,捡一块3865U工控板

150 元打造低成本 NAS 小钢炮,捡一块 3865U 工控板 一块二手的熊猫 B3 工控板 3865U,搭...
支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare 也瘫了连监控都挂,根因藏在哪? 最近两天的互联网堪称“故障...
恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击

恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击

恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击 PHP-FPM(FastCGl Process M...