1 查看Linux发行版本
[root@typecodes~]#cat/etc/redhat-release CentOSLinuxrelease7.2.1511(Core)
2 下载MysqL官方的Yum Repository
根据Linux发行版本(CentOS、Fedora都属于红帽系),从MysqL官方(http://dev.MysqL.com/downloads/repo/yum/)获取Yum Repository。
[root@typecodes~]#wget-ihttp://dev.MysqL.com/get/MysqL57-community-release-el7-7.noarch.rpm --2016-02-0318:36:02--http://dev.MysqL.com/get/MysqL57-community-release-el7-7.noarch.rpm Resolvingdev.MysqL.com(dev.MysqL.com)...137.254.60.11 Connectingtodev.MysqL.com(dev.MysqL.com)|137.254.60.11|:80...connected. HTTPrequestsent,awaitingresponse...302Found Location:http://repo.MysqL.com//MysqL57-community-release-el7-7.noarch.rpm[following] --2016-02-0318:36:04--http://repo.MysqL.com//MysqL57-community-release-el7-7.noarch.rpm Resolvingrepo.MysqL.com(repo.MysqL.com)...104.102.164.25 Connectingtorepo.MysqL.com(repo.MysqL.com)|104.102.164.25|:80...connected. HTTPrequestsent,awaitingresponse...200OK Length:8984(8.8K)[application/x-redhat-package-manager] Savingto:‘MysqL57-community-release-el7-7.noarch.rpm’ 100%[=============================================================================================================================>]8,984--.-K/sin0s 2016-02-0318:36:07(68.4MB/s)-‘MysqL57-community-release-el7-7.noarch.rpm’saved[8984/8984]
3 安装MysqL的Yum Repository
安装完MysqL的Yum Repository,每次执行yum update都会检查MysqL是否更新。
[root@typecodes~]#yum-yinstallMysqL57-community-release-el7-7.noarch.rpm Loadedplugins:axelget,fastestmirror,langpacks ExaminingMysqL57-community-release-el7-7.noarch.rpm:MysqL57-community-release-el7-7.noarch MarkingMysqL57-community-release-el7-7.noarch.rpmtobeinstalled ResolvingDependencies -->Runningtransactioncheck --->PackageMysqL57-community-release.noarch0:el7-7willbeinstalled -->FinishedDependencyResolution DependenciesResolved ======================================================================================================================================================================= PackageArchVersionRepositorySize ======================================================================================================================================================================= Installing: MysqL57-community-releasenoarchel7-7/MysqL57-community-release-el7-7.noarch7.8k TransactionSummary ======================================================================================================================================================================= Install1Package Totalsize:7.8k Installedsize:7.8k Downloadingpackages: Runningtransactioncheck Runningtransactiontest Transactiontestsucceeded Runningtransaction Installing:MysqL57-community-release-el7-7.noarch1/1 Verifying:MysqL57-community-release-el7-7.noarch1/1 Installed: MysqL57-community-release.noarch0:el7-7 Complete!
3 安装MysqL数据库的服务器版本
[root@typecodes~]#yum-yinstallMysqL-community-server Loadedplugins:axelget,langpacks NoMetadataavailableforbase NoMetadataavailableforepel NoMetadataavailableforextras repomd.xml|2.5kB00:00:00 updateMysqL-connectors-communityMetadatasuccessfully repomd.xml|2.5kB00:00:00 updateMysqL-tools-communityMetadatasuccessfully repomd.xml|2.5kB00:00:00 updateMysqL57-communityMetadatasuccessfully NoMetadataavailableforupdates MysqL-connectors-community|2.5kB00:00:00 MysqL-tools-community|2.5kB00:00:00 MysqL57-community|2.5kB00:00:00 (1/3):MysqL-tools-community/x86_64/primary_db|24kB00:00:01 (2/3):MysqL57-community/x86_64/primary_db|28kB00:00:01 (3/3):MysqL-connectors-community/x86_64/primary_db|8.6kB00:00:02 Loadingmirrorspeedsfromcachedhostfile *base:mirrors.aliyun.com *epel:mirrors.neusoft.edu.cn *extras:mirrors.163.com *updates:mirrors.163.com ResolvingDependencies -->Runningtransactioncheck --->PackageMysqL-community-server.x86_640:5.7.10-1.el7willbeinstalled -->ProcessingDependency:MysqL-community-common(x86-64)=5.7.10-1.el7forpackage:MysqL-community-server-5.7.10-1.el7.x86_64 -->ProcessingDependency:MysqL-community-client(x86-64)=5.7.10-1.el7forpackage:MysqL-community-server-5.7.10-1.el7.x86_64 -->Runningtransactioncheck --->PackageMysqL-community-client.x86_640:5.7.10-1.el7willbeinstalled -->ProcessingDependency:MysqL-community-libs(x86-64)=5.7.10-1.el7forpackage:MysqL-community-client-5.7.10-1.el7.x86_64 --->PackageMysqL-community-common.x86_640:5.7.10-1.el7willbeinstalled -->Runningtransactioncheck --->Packagemariadb-libs.x86_641:5.5.44-2.el7.centoswillbeobsoleted -->ProcessingDependency:libMysqLclient.so.18()(64bit)forpackage:2:postfix-2.10.1-6.el7.x86_64 -->ProcessingDependency:libMysqLclient.so.18(libMysqLclient_18)(64bit)forpackage:2:postfix-2.10.1-6.el7.x86_64 --->PackageMysqL-community-libs.x86_640:5.7.10-1.el7willbeobsoleting -->Runningtransactioncheck --->PackageMysqL-community-libs-compat.x86_640:5.7.10-1.el7willbeobsoleting -->FinishedDependencyResolution DependenciesResolved ======================================================================================================================================================================= PackageArchVersionRepositorySize ======================================================================================================================================================================= Installing: MysqL-community-libsx86_645.7.10-1.el7MysqL57-community2.2M replacingmariadb-libs.x86_641:5.5.44-2.el7.centos MysqL-community-libs-compatx86_645.7.10-1.el7MysqL57-community2.0M replacingmariadb-libs.x86_641:5.5.44-2.el7.centos MysqL-community-serverx86_645.7.10-1.el7MysqL57-community142M Installingfordependencies: MysqL-community-clientx86_645.7.10-1.el7MysqL57-community24M MysqL-community-commonx86_645.7.10-1.el7MysqL57-community269k TransactionSummary ======================================================================================================================================================================= Install3Packages(+2Dependentpackages) Totaldownloadsize:171M Downloadingpackages: MysqL-community-server-5.7.10-1.el7.x86_64.rpm|142MB00:03:42 MysqL-community-libs-compat-5.7.10-1.el7.x86_64.rpm|2.0MB00:00:03 MysqL-community-libs-5.7.10-1.el7.x86_64.rpm|2.2MB00:00:05 MysqL-community-client-5.7.10-1.el7.x86_64.rpm|24MB00:00:41 warning:/var/cache/yum/x86_64/7/MysqL57-community/packages/MysqL-community-common-5.7.10-1.el7.x86_64.rpm:HeaderV3DSA/SHA1Signature,keyID5072e1f5:NOKEY00ETA PublickeyforMysqL-community-common-5.7.10-1.el7.x86_64.rpmisnotinstalled MysqL-community-common-5.7.10-1.el7.x86_64.rpm|269kB00:00:01 Retrievingkeyfromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL ImportingGPGkey0x5072E1F5: Userid:"MysqLReleaseEngineering<MysqL-build@oss.oracle.com>" Fingerprint:a4a9406876fcbd3c456770c88c718d3b5072e1f5 Package:MysqL57-community-release-el7-7.noarch(@/MysqL57-community-release-el7-7.noarch) From:/etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL Runningtransactioncheck Runningtransactiontest Transactiontestsucceeded Runningtransaction Installing:MysqL-community-common-5.7.10-1.el7.x86_641/6 Installing:MysqL-community-libs-5.7.10-1.el7.x86_642/6 Installing:MysqL-community-client-5.7.10-1.el7.x86_643/6 Installing:MysqL-community-server-5.7.10-1.el7.x86_644/6 Installing:MysqL-community-libs-compat-5.7.10-1.el7.x86_645/6 Erasing:1:mariadb-libs-5.5.44-2.el7.centos.x86_646/6 Verifying:MysqL-community-server-5.7.10-1.el7.x86_641/6 Verifying:MysqL-community-libs-compat-5.7.10-1.el7.x86_642/6 Verifying:MysqL-community-common-5.7.10-1.el7.x86_643/6 Verifying:MysqL-community-libs-5.7.10-1.el7.x86_644/6 Verifying:MysqL-community-client-5.7.10-1.el7.x86_645/6 Verifying:1:mariadb-libs-5.5.44-2.el7.centos.x86_646/6 Installed: MysqL-community-libs.x86_640:5.7.10-1.el7MysqL-community-libs-compat.x86_640:5.7.10-1.el7MysqL-community-server.x86_640:5.7.10-1.el7 DependencyInstalled: MysqL-community-client.x86_640:5.7.10-1.el7MysqL-community-common.x86_640:5.7.10-1.el7 Replaced: mariadb-libs.x86_641:5.5.44-2.el7.centos Complete! [root@typecodes~]#clear
最后的截图:
4 启动数据库:
[root@typecodes~]#systemctlstartMysqLd.service
然后使用命令systemctl status MysqLd.service
查看MysqL数据库启动后的服务状态:
5 获取初始密码
使用YUM安装并启动MysqL服务后,MysqL进程会自动在进程日志中打印root用户的初始密码:
#######从MysqL进程日志中获取root用户的初始密码:ra%yk7urCBIh [root@typecodes~]#grep"password"/var/log/MysqLd.log 2016-02-03T10:42:17.272166Z1[Note]Atemporarypasswordisgeneratedforroot@localhost:ra%yk7urCBIh 2016-02-03T10:42:36.776875Z2[Note]Accessdeniedforuser'root'@'localhost'(usingpassword:NO) 2016-02-03T10:42:52.063138Z3[Note]Accessdeniedforuser'root'@'localhost'(usingpassword:NO) 2016-02-03T10:42:57.564373Z4[Note]Accessdeniedforuser'root'@'localhost'(usingpassword:NO) 2016-02-03T10:43:01.477007Z5[Note]Accessdeniedforuser'root'@'localhost'(usingpassword:NO) 2016-02-03T10:46:03.642008Z6[Note]Accessdeniedforuser'root'@'localhost'(usingpassword:NO) 2016-02-03T10:46:11.217889Z7[Note]Accessdeniedforuser'root'@'localhost'(usingpassword:NO) 2016-02-03T10:47:44.755199Z0[Note]Shuttingdownplugin'validate_password' 2016-02-03T10:47:46.505844Z0[Note]Shuttingdownplugin'sha256_password' 2016-02-03T10:47:46.505851Z0[Note]Shuttingdownplugin'MysqL_native_password'
6 修改root用户密码
[root@typecodes~]#MysqL-uroot-p Enterpassword:#######输入默认的root密码后回车 WelcometotheMysqLmonitor.Commandsendwith;or\g. YourMysqLconnectionidis2 Serverversion:5.7.10 Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MysqL>ALTERUSER'root'@'localhost'IDENTIFIEDBY'newpassword'; QueryOK,0rowsaffected(0.00sec) MysqL>exit Bye
7 安装完毕
至此,使用在CentOS7中使用YUM方法安装MysqL5.7.10数据库完毕。如下所示,可以使用新的root密码登陆MysqL了。
[root@typecodes~]#MysqL-uroot-ppassword MysqL:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure. WelcometotheMysqLmonitor.Commandsendwith;or\g. YourMysqLconnectionidis3 Serverversion:5.7.10MysqLCommunityServer(GPL) Copyright(c)2000,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MysqL>useMysqL; Readingtableinformationforcompletionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged MysqL>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |MysqL| |performance_schema| |sys| +--------------------+ 4rowsinset(0.00sec) MysqL>clear MysqL>exit Bye [root@typecodes~]#clear
附录1:查看MysqL数据库的配置信息
MysqL的配置文件依然是/etc/my.cnf
,其它安装信息可以通过MysqL_config
命令查看。其中,动态库文件存放在/usr/lib64/MysqL
目录下。
附录2:对于C/C++等开发者
由于需要用到类似MysqL.h等头文件,需要执行下面的命令安装MysqL开发版本即可。
[root@typecodes~]#yum-yinstallMysqL-community-devel
附录3:删除MysqL的Repository
因为小节3中安装了MysqL的Yum Repository,所以以后每次执行yum操作时,都会去检查更新。如果想要去掉这种自动检查操作的话,可以使用如下命令卸载MysqL的Repository即可。
[root@typecodes~]#yum-yremoveMysqL57-community-release-el7-7.noarch
update 2017.04.10 11:10
使用上面的yum方法也可以安装目前MysqL官网上最新的版本MysqL5.7.18。只要替换小节2中rmp包的版本即可,后续操作步骤不变。
wget-i-chttp://dev.MysqL.com/get/MysqL57-community-release-el7-10.noarch.rpm原文链接:https://www.f2er.com/bash/391973.html