热门标签 | HotTags
当前位置:  开发笔记 > 后端 > 正文

CentOS7.464位安装配置MySQL8.0的详细步骤

本文分步骤给大家介绍了CentOS7.464位安装配置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

这里有三条搜索结果,因为我重复装了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 'Pwd123@easyoh.net';
Query OK, 0 rows affected (0.03 sec)
mysql>

Pwd123@easyoh.net 请替换成你自己的密码。

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

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

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

mysql> CREATE USER 'easyoh-mp'@'%' IDENTIFIED BY 'Pwd123@easyoh.net';
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 changed
mysql> 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 'Pwd123@easyoh.net' PASSWORD EXPIRE NEVER; 
Query OK, 0 rows affected (0.04 sec)
mysql> ALTER USER 'easyoh-mp'@'%' IDENTIFIED WITH mysql_native_password BY 'Pwd123@easyoh.net'; 
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 ALTER USER 'root'@'localhost' IDENTIFIED BY 'Pwd123@easyoh.net';
Query OK, 0 rows affected (0.03 sec)
mysql> CREATE USER 'easyoh-mp'@'%' IDENTIFIED BY 'Pwd123@easyoh.net';
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 changed
mysql> 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 'Pwd123@easyoh.net' PASSWORD EXPIRE NEVER; 
Query OK, 0 rows affected (0.04 sec)
mysql> ALTER USER 'easyoh-mp'@'%' IDENTIFIED WITH mysql_native_password BY 'Pwd123@easyoh.net'; 
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的详细步骤,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!


推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 本文介绍了使用postman进行接口测试的方法,以测试用户管理模块为例。首先需要下载并安装postman,然后创建基本的请求并填写用户名密码进行登录测试。接下来可以进行用户查询和新增的测试。在新增时,可以进行异常测试,包括用户名超长和输入特殊字符的情况。通过测试发现后台没有对参数长度和特殊字符进行检查和过滤。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 数据库(外键及其约束理解)(https:www.cnblogs.comchenxiaoheip6909318.html)My ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • yum安装_Redis —yum安装全过程
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Redis—yum安装全过程相关的知识,希望对你有一定的参考价值。访问https://redi ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • 本文介绍了通过mysql命令查看mysql的安装路径的方法,提供了相应的sql语句,并希望对读者有参考价值。 ... [详细]
  • 本文详细介绍了MySQL表分区的创建、增加和删除方法,包括查看分区数据量和全库数据量的方法。欢迎大家阅读并给予点评。 ... [详细]
  • Oracle10g备份导入的方法及注意事项
    本文介绍了使用Oracle10g进行备份导入的方法及相关注意事项,同时还介绍了2019年独角兽企业重金招聘Python工程师的标准。内容包括导出exp命令、删用户、创建数据库、授权等操作,以及导入imp命令的使用。详细介绍了导入时的参数设置,如full、ignore、buffer、commit、feedback等。转载来源于https://my.oschina.net/u/1767754/blog/377593。 ... [详细]
  • mysql-cluster集群sql节点高可用keepalived的故障处理过程
    本文描述了mysql-cluster集群sql节点高可用keepalived的故障处理过程,包括故障发生时间、故障描述、故障分析等内容。根据keepalived的日志分析,发现bogus VRRP packet received on eth0 !!!等错误信息,进而导致vip地址失效,使得mysql-cluster的api无法访问。针对这个问题,本文提供了相应的解决方案。 ... [详细]
author-avatar
qgd2013_184
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有