怎么怎么CentOS 7.4 64位系统中安装MySQL8.0?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

第一步:获取mysql YUM源


点击下载

第二步:下载和安装mysql源

•进入mysql文件夹,没有的自行创建

[root@VM_0_10_centos/]#cd/usr/local/mysql/[root@VM_0_10_centosmysql]#

•下载源安装包

[root@VM_0_10_centosmysql]#wgethttps://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm--2018-08-0410:29:39--https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpmResolvingrepo.mysql.com(repo.mysql.com)...23.219.33.198Connectingtorepo.mysql.com(repo.mysql.com)|23.219.33.198|:443...connected.HTTPrequestsent,awaitingresponse...200OKLength:25820(25K)[application/x-redhat-package-manager]Savingto:‘mysql80-community-release-el7-1.noarch.rpm'100%[==========================================================================>]25,820112KB/sin0.2s2018-08-0410:29:40(112KB/s)-‘mysql80-community-release-el7-1.noarch.rpm'saved[25820/25820][root@VM_0_10_centosmysql]#lltotal28-rw-r--r--1rootroot25820Apr1813:24mysql80-community-release-el7-1.noarch.rpm[root@VM_0_10_centosmysql]#

•安装mysql源

[root@VM_0_10_centosmysql]#yum-ylocalinstallmysql80-community-release-el7-1.noarch.rpm

第三步:在线安装MySQL

[root@VM_0_10_centosmysql]#yum-yinstallmysql-community-server

下载东西比较多,等几分钟。

第四步:启动Mysql服务

[root@VM_0_10_centosmysql]#systemctlstartmysqld

第五步:设置开机启动

[root@VM_0_10_centosmysql]#systemctlenablemysqld[root@VM_0_10_centosmysql]#systemctldaemon-reload

第六步:修改root本地登录密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。用grep命令搜一下

[root@VM_0_10_centosmysql]#grep"Atemporarypasswordisgeneratedforroot@localhost"/var/log/mysqld.log2018-08-02T02:19:55.829527Z5[Note][MY-010454][Server]Atemporarypasswordisgeneratedforroot@localhost:!J:KUwU9y0ZR2018-08-02T04:49:34.979689Z5[Note][MY-010454][Server]Atemporarypasswordisgeneratedforroot@localhost:pw</s9,Wivm22018-08-04T02:40:46.781768Z5[Note][MY-010454][Server]Atemporarypasswordisgeneratedforroot@localhost:nNyK,Y)Wd0-G[root@VM_0_10_centosmysql]#

这里有三条搜索结果,因为我重复装了3次MySQL,如果第一次安装是只会有一条的。

直接拿到临时默认密码 : nNyK,Y)Wd0-G

•登录MySQL

[root@VM_0_10_centosmysql]#mysql-uroot-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis8Serverversion:8.0.12Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>

•更改root账户临时密码

mysql>ALTERUSER'root'@'localhost'IDENTIFIEDBY'Pwd123@easyoh.net';QueryOK,0rowsaffected(0.03sec)mysql>

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

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

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

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

mysql>CREATEUSER'easyoh-mp'@'%'IDENTIFIEDBY'Pwd123@easyoh.net';QueryOK,0rowsaffected(0.04sec)mysql>GRANTALLON*.*TO'easyoh-mp'@'%';QueryOK,0rowsaffected(0.03sec)mysql>

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

发现会报plugin caching_sha2_password错误。这是因为MySQL8.0密码策略默认为caching_sha2_password。与5.7有所不同。

•进入MySQL数据库查询user表信息

mysql>usemysql;Databasechangedmysql>selectuser,host,pluginfromuser;+------------------+-----------+-----------------------+|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|+------------------+-----------+-----------------------+5rowsinset(0.00sec)mysql>

发现确实是caching_sha2_password

•依次执行下面语句

mysql>ALTERUSER'easyoh-mp'@'%'IDENTIFIEDBY'Pwd123@easyoh.net'PASSWORDEXPIRENEVER;QueryOK,0rowsaffected(0.04sec)mysql>ALTERUSER'easyoh-mp'@'%'IDENTIFIEDWITHmysql_native_passwordBY'Pwd123@easyoh.net';QueryOK,0rowsaffected(0.05sec)mysql>FLUSHPRIVILEGES;QueryOK,0rowsaffected(0.01sec)mysql>

再次登录就可以登录成功了。

第8步:编码

mysql>showvariableslike'%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/|+--------------------------+--------------------------------+8rowsinset(0.01sec)mysql>

MySQL8.0默认就是utf8mb4编码,无需更改。

OK 至此 Mysql安装配置完毕;

全流程操作记录

[root@VM_0_10_centos~]#[root@VM_0_10_centos/]#cd/usr/local/mysql/[root@VM_0_10_centosmysql]#wgethttps://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm--2018-08-0410:29:39--https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpmResolvingrepo.mysql.com(repo.mysql.com)...23.219.33.198Connectingtorepo.mysql.com(repo.mysql.com)|23.219.33.198|:443...connected.HTTPrequestsent,awaitingresponse...200OKLength:25820(25K)[application/x-redhat-package-manager]Savingto:‘mysql80-community-release-el7-1.noarch.rpm'100%[==========================================================================>]25,820112KB/sin0.2s2018-08-0410:29:40(112KB/s)-‘mysql80-community-release-el7-1.noarch.rpm'saved[25820/25820][root@VM_0_10_centosmysql]#lltotal28-rw-r--r--1rootroot25820Apr1813:24mysql80-community-release-el7-1.noarch.rpm[root@VM_0_10_centosmysql]#yum-ylocalinstallmysql80-community-release-el7-1.noarch.rpmLoadedplugins:fastestmirror,langpacksExaminingmysql80-community-release-el7-1.noarch.rpm:mysql80-community-release-el7-1.noarchMarkingmysql80-community-release-el7-1.noarch.rpmtobeinstalledResolvingDependencies-->Runningtransactioncheck--->Packagemysql80-community-release.noarch0:el7-1willbeinstalled-->FinishedDependencyResolutionDependenciesResolved=================================================================================================================================================================================================================PackageArchVersionRepositorySize=================================================================================================================================================================================================================Installing:mysql80-community-releasenoarchel7-1/mysql80-community-release-el7-1.noarch31kTransactionSummary=================================================================================================================================================================================================================Install1PackageTotalsize:31kInstalledsize:31kDownloadingpackages:RunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionWarning:RPMDBalteredoutsideofyum.Installing:mysql80-community-release-el7-1.noarch1/1Verifying:mysql80-community-release-el7-1.noarch1/1Installed:mysql80-community-release.noarch0:el7-1Complete![root@VM_0_10_centosmysql]#yum-yinstallmysql-community-serverLoadedplugins:fastestmirror,langpacksLoadingmirrorspeedsfromcachedhostfileepel12641/12641ResolvingDependencies-->Runningtransactioncheck--->Packagemysql-community-server.x86_640:8.0.12-1.el7willbeinstalled-->ProcessingDependency:mysql-community-common(x86-64)=8.0.12-1.el7forpackage:mysql-community-server-8.0.12-1.el7.x86_64-->ProcessingDependency:mysql-community-client(x86-64)>=8.0.0forpackage:mysql-community-server-8.0.12-1.el7.x86_64-->Runningtransactioncheck--->Packagemysql-community-client.x86_640:8.0.12-1.el7willbeinstalled-->ProcessingDependency:mysql-community-libs(x86-64)>=8.0.0forpackage:mysql-community-client-8.0.12-1.el7.x86_64--->Packagemysql-community-common.x86_640:8.0.12-1.el7willbeinstalled-->Runningtransactioncheck--->Packagemysql-community-libs.x86_640:8.0.12-1.el7willbeinstalled-->FinishedDependencyResolutionDependenciesResolved=================================================================================================================================================================================================================PackageArchVersionRepositorySize=================================================================================================================================================================================================================Installing:mysql-community-serverx86_648.0.12-1.el7mysql80-community349MInstallingfordependencies:mysql-community-clientx86_648.0.12-1.el7mysql80-community26Mmysql-community-commonx86_648.0.12-1.el7mysql80-community541kmysql-community-libsx86_648.0.12-1.el7mysql80-community2.2MTransactionSummary=================================================================================================================================================================================================================Install1Package(+3Dependentpackages)Totaldownloadsize:377MInstalledsize:1.7GDownloadingpackages:(1/4):mysql-community-common-8.0.12-1.el7.x86_64.rpm|541kB00:00:05(2/4):mysql-community-client-8.0.12-1.el7.x86_64.rpm|26MB00:00:12(3/4):mysql-community-server-8.0.12-1.el7.x86_64.rpm|349MB00:02:26(4/4):mysql-community-libs-8.0.12-1.el7.x86_64.rpm|2.2MB00:03:37-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total1.7MB/s|377MB00:03:43RunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionInstalling:mysql-community-common-8.0.12-1.el7.x86_641/4Installing:mysql-community-libs-8.0.12-1.el7.x86_642/4Installing:mysql-community-client-8.0.12-1.el7.x86_643/4Installing:mysql-community-server-8.0.12-1.el7.x86_644/4Verifying:mysql-community-common-8.0.12-1.el7.x86_641/4Verifying:mysql-community-libs-8.0.12-1.el7.x86_642/4Verifying:mysql-community-client-8.0.12-1.el7.x86_643/4Verifying:mysql-community-server-8.0.12-1.el7.x86_644/4Installed:mysql-community-server.x86_640:8.0.12-1.el7DependencyInstalled:mysql-community-client.x86_640:8.0.12-1.el7mysql-community-common.x86_640:8.0.12-1.el7mysql-community-libs.x86_640:8.0.12-1.el7Complete![root@VM_0_10_centosmysql]#systemctlstartmysqld[root@VM_0_10_centosmysql]#systemctlenablemysqld[root@VM_0_10_centosmysql]#systemctldaemon-reload[root@VM_0_10_centosmysql]#grep"Atemporarypasswordisgeneratedforroot@localhost"/var/log/mysqld.log2018-08-02T02:19:55.829527Z5[Note][MY-010454][Server]Atemporarypasswordisgeneratedforroot@localhost:!J:KUwU9y0ZR2018-08-02T04:49:34.979689Z5[Note][MY-010454][Server]Atemporarypasswordisgeneratedforroot@localhost:pw</s9,Wivm22018-08-04T02:40:46.781768Z5[Note][MY-010454][Server]Atemporarypasswordisgeneratedforroot@localhost:nNyK,Y)Wd0-G[root@VM_0_10_centosmysql]#mysql-uroot-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis8Serverversion:8.0.12Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>ALTERUSER'root'@'localhost'IDENTIFIEDBY'Pwd123@easyoh.net';QueryOK,0rowsaffected(0.03sec)mysql>CREATEUSER'easyoh-mp'@'%'IDENTIFIEDBY'Pwd123@easyoh.net';QueryOK,0rowsaffected(0.04sec)mysql>GRANTALLON*.*TO'easyoh-mp'@'%';QueryOK,0rowsaffected(0.03sec)mysql>usemysql;Databasechangedmysql>selectuser,host,pluginfromuser;+------------------+-----------+-----------------------+|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|+------------------+-----------+-----------------------+5rowsinset(0.00sec)mysql>ALTERUSER'easyoh-mp'@'%'IDENTIFIEDBY'Pwd123@easyoh.net'PASSWORDEXPIRENEVER;QueryOK,0rowsaffected(0.04sec)mysql>ALTERUSER'easyoh-mp'@'%'IDENTIFIEDWITHmysql_native_passwordBY'Pwd123@easyoh.net';QueryOK,0rowsaffected(0.05sec)mysql>FLUSHPRIVILEGES;QueryOK,0rowsaffected(0.01sec)mysql>showvariableslike'%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/|+--------------------------+--------------------------------+8rowsinset(0.01sec)

这里有个问题,新密码设置的时候如果设置的过于简单会报错:

原因是因为MySQL有密码设置的规范,具体是与validate_password_policy的值有关:

MySQL完整的初始密码规则可以通过如下命令查看:

mysql>SHOWVARIABLESLIKE'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|+--------------------------------------+-------+7rowsinset(0.01sec)

密码的长度是由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>setglobalvalidate_password_policy=0;mysql>setglobalvalidate_password_length=1;

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。