欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-27 14:57:52
第一步:获取mysql yum源 进入mysql官网获取rpm包下载地址 点击下载 获取到下载链接: -----------------------...

第一步:获取mysql yum源

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

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

点击下载

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

获取到下载链接:

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

第二步:下载和安装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 '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账户登录(其他客户端也可以,随意)

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  |
+------------------+-----------+-----------------------+
| 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</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 '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的值有关:

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

  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的详细步骤,希望对大家有所帮助