CentOS 7.4 64位安装配置MySQL8.0

最近新买了一台云服务器,需要安装MySQL8.0数据库,百度了几个教程,发现大都有所缺漏,于是自己摸索着安装,亲测成功。最后将安装过程记录下来分享给大家。


第一步:获取mysql YUM源

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

image.png

点击下载

image.png

获取到下载链接:
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 '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账户登录(其他客户端也可以,随意)
image.png

发现会报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)

欢迎留言讨论。欢迎转载,转载请务必注明出处。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,294评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,493评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,790评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,595评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,718评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,906评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,053评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,797评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,250评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,570评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,711评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,388评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,018评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,796评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,023评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,461评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,595评论 2 350

推荐阅读更多精彩内容