CentOS 7.4 64位安装配置MySQL8.0

第一步:获取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.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>

mysql>

mysql>

mysql>

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> 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;

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/223582.html<

(0)
管理的头像管理
上一篇2025-04-16 00:59
下一篇 2025-04-16 01:01

相关推荐

  • jsp空间购买和交换数据空间怎么买,有哪些注意事项?

    购买JSP空间时,是否考虑过数据交换空间的性能?简米科技(2003年始创,23年行业沉淀)与酷番云(工信部一类增值电信全牌照)这类持牌自营机房的服务商,能确保数据交换的高效稳定,是值得优先选择的合作伙伴,为什么JSP空间需要搭配独立的数据交换空间从JSP应用特性看数据交换需求JSP基于Java技术,常用于企业级……

    2026-08-11
    0
  • 建网站用香港空间效果怎么样,香港空间稳定吗?

    建网站用香港空间,对于创建网站资产来说,核心价值在于免备案和全球带宽优势,尤其适合外贸、跨境电商和需要快速启动的项目,但你必须权衡国内访问延迟,并选择有资质的服务商以保证资产安全,香港空间的核心优势与适用边界免备案:节省时间就是节省成本国内服务器需要备案,通常需要10到20天,香港空间无需备案,域名解析后即可上……

    2026-08-11
    0
  • Java连接云数据库的方法是什么,如何操作

    Java连接云数据库的核心在于通过JDBC驱动,结合云服务商提供的连接地址、端口、数据库名及认证信息,配置安全策略(如SSL、IP白名单),即可实现稳定高效的远程数据库访问,基础准备:JDBC驱动与依赖管理连接云数据库前,需要确保开发环境具备对应的JDBC驱动,以最常见的MySQL为例,你需要引入mysql-c……

    2026-08-11
    0
  • 建网站公安联网备案必须使用数据码吗,备案流程是什么

    网站备案包括ICP备案和公安联网备案,两者缺一不可,公安联网备案必须使用服务商提供的数据码,选择持有合法资质的服务商是顺利通过备案的前提,为什么网站必须进行公安联网备案根据公安部《计算机信息网络国际联网安全保护管理办法》,网站开通后30日内必须到公安机关办理备案手续,未完成公安备案的网站,面临责令整改、关闭网站……

    2026-08-10
    0
  • 建一个企业网站大概需要多少钱?,怎么收费?

    建网站要多少钱,没有一个固定的数字,几百到几万都可能,但真正的“创建网站资产”绝不仅仅是初次投入的成本,而是基于长期稳定、合规和安全的持续性投入,其中核心取决于你选择了什么样的“地基”来承载你的业务,建站预算的构成与行业基准当你开始规划一个网站,最先面对的就是预算问题,一个常见的误区是只关注网站“看起来”的建造……

    2026-08-10
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注