• ADADADADAD

    centos7.3 安装mysql5.7.18的示例[ mysql数据库 ]

    mysql数据库 时间:2024-11-29 09:51:16

    作者:文/会员上传

    简介:

    1查看Linux发行版本[root@typecodes ~]# cat /etc/redhat-releaseCentOS Linux release 7.2.1511 (Core)2 下载MySQL官方的Yum Repository根据Linux发行版本(CentOS、Fedora

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    1查看Linux发行版本

    [root@typecodes ~]# cat /etc/redhat-release
    CentOS Linux release 7.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.rpmResolvingdev.mysql.com(dev.mysql.com)...137.254.60.11Connectingtodev.mysql.com(dev.mysql.com)|137.254.60.11|:80...connected.HTTPrequestsent,awaitingresponse...302FoundLocation: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.rpmResolvingrepo.mysql.com(repo.mysql.com)...104.102.164.25Connectingtorepo.mysql.com(repo.mysql.com)|104.102.164.25|:80...connected.HTTPrequestsent,awaitingresponse...200OKLength:8984(8.8K)[application/x-redhat-package-manager]Savingto:‘mysql57-community-release-el7-7.noarch.rpm'100%[=============================================================================================================================>]8,984--.-K/sin0s2016-02-0318:36:07(68.4MB/s)-‘mysql57-community-release-el7-7.noarch.rpm'saved[8984/8984]3安装MySQL的YumRepository安装完MySQL的YumRepository,每次执行yumupdate都会检查MySQL是否更新。[root@typecodes~]#yum-yinstallmysql57-community-release-el7-7.noarch.rpmLoadedplugins:axelget,fastestmirror,langpacksExaminingmysql57-community-release-el7-7.noarch.rpm:mysql57-community-release-el7-7.noarchMarkingmysql57-community-release-el7-7.noarch.rpmtobeinstalledResolvingDependencies-->Runningtransactioncheck--->Packagemysql57-community-release.noarch0:el7-7willbeinstalled-->FinishedDependencyResolutionDependenciesResolved=======================================================================================================================================================================PackageArchVersionRepositorySize=======================================================================================================================================================================Installing:mysql57-community-releasenoarchel7-7/mysql57-community-release-el7-7.noarch7.8kTransactionSummary=======================================================================================================================================================================Install1PackageTotalsize:7.8kInstalledsize:7.8kDownloadingpackages:RunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionInstalling:mysql57-community-release-el7-7.noarch1/1Verifying:mysql57-community-release-el7-7.noarch1/1Installed:mysql57-community-release.noarch0:el7-7Complete!

    3 安装MySQL数据库的服务器版本

    [root@typecodes~]#yum-yinstallmysql-community-serverLoadedplugins:axelget,fastestmirror,langpacksNometadataavailableforbaseNometadataavailableforepelNometadataavailableforextrasrepomd.xml|2.5kB00:00:00updatemysql-connectors-communitymetadatasuccessfullyrepomd.xml|2.5kB00:00:00updatemysql-tools-communitymetadatasuccessfullyrepomd.xml|2.5kB00:00:00updatemysql57-communitymetadatasuccessfullyNometadataavailableforupdatesmysql-connectors-community|2.5kB00:00:00mysql-tools-community|2.5kB00:00:00mysql57-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:02Loadingmirrorspeedsfromcachedhostfile*base:mirrors.aliyun.com*epel:mirrors.neusoft.edu.cn*extras:mirrors.163.com*updates:mirrors.163.comResolvingDependencies-->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-->FinishedDependencyResolutionDependenciesResolved=======================================================================================================================================================================PackageArchVersionRepositorySize=======================================================================================================================================================================Installing:mysql-community-libsx86_645.7.10-1.el7mysql57-community2.2Mreplacingmariadb-libs.x86_641:5.5.44-2.el7.centosmysql-community-libs-compatx86_645.7.10-1.el7mysql57-community2.0Mreplacingmariadb-libs.x86_641:5.5.44-2.el7.centosmysql-community-serverx86_645.7.10-1.el7mysql57-community142MInstallingfordependencies:mysql-community-clientx86_645.7.10-1.el7mysql57-community24Mmysql-community-commonx86_645.7.10-1.el7mysql57-community269kTransactionSummary=======================================================================================================================================================================Install3Packages(+2Dependentpackages)Totaldownloadsize:171MDownloadingpackages:mysql-community-server-5.7.10-1.el7.x86_64.rpm|142MB00:03:42mysql-community-libs-compat-5.7.10-1.el7.x86_64.rpm|2.0MB00:00:03mysql-community-libs-5.7.10-1.el7.x86_64.rpm|2.2MB00:00:05mysql-community-client-5.7.10-1.el7.x86_64.rpm|24MB00:00:41warning:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.10-1.el7.x86_64.rpm:HeaderV3DSA/SHA1Signature,keyID5072e1f5:NOKEY00ETAPublickeyformysql-community-common-5.7.10-1.el7.x86_64.rpmisnotinstalledmysql-community-common-5.7.10-1.el7.x86_64.rpm|269kB00:00:01Retrievingkeyfromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlImportingGPGkey0x5072E1F5:Userid:"MySQLReleaseEngineering<mysql-build@oss.oracle.com>"Fingerprint:a4a9406876fcbd3c456770c88c718d3b5072e1f5Package:mysql57-community-release-el7-7.noarch(@/mysql57-community-release-el7-7.noarch)From:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlRunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionInstalling:mysql-community-common-5.7.10-1.el7.x86_641/6Installing:mysql-community-libs-5.7.10-1.el7.x86_642/6Installing:mysql-community-client-5.7.10-1.el7.x86_643/6Installing:mysql-community-server-5.7.10-1.el7.x86_644/6Installing:mysql-community-libs-compat-5.7.10-1.el7.x86_645/6Erasing:1:mariadb-libs-5.5.44-2.el7.centos.x86_646/6Verifying:mysql-community-server-5.7.10-1.el7.x86_641/6Verifying:mysql-community-libs-compat-5.7.10-1.el7.x86_642/6Verifying:mysql-community-common-5.7.10-1.el7.x86_643/6Verifying:mysql-community-libs-5.7.10-1.el7.x86_644/6Verifying:mysql-community-client-5.7.10-1.el7.x86_645/6Verifying:1:mariadb-libs-5.5.44-2.el7.centos.x86_646/6Installed: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.el7DependencyInstalled:mysql-community-client.x86_640:5.7.10-1.el7mysql-community-common.x86_640:5.7.10-1.el7Replaced:mariadb-libs.x86_641:5.5.44-2.el7.centosComplete![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.log2016-02-03T10:42:17.272166Z1[Note]Atemporarypasswordisgeneratedforroot@localhost:ra%yk7urCBIh2016-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用户密码

    使用小节5中获取的root用户的初始密码,然后进行修改:

    set global validate_password_policy =0;//默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

    setglobalvalidate_password_length=4;//指定了密码中数据的长度alteruserroot@localhostidentifiedby'crow';//修改密码

    增加远程访问权限

    GRANTALLPRIVILEGESON*.*TO'root'@'%'IDENTIFIEDBY'crow'WITHGRANTOPTION;FLUSHPRIVILEGES;

    退出mysql,然后重启服务

    systemctlrestartmysqld

    防火墙打开3306端口

    firewall-cmd--zone=public--add-port=3306/tcp--permanent

    重启防火墙

    firewall-cmd--reload[root@typecodes~]#mysql-uroot-pEnterpassword:#######输入默认的root密码后回车WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis2Serverversion:5.7.10Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>ALTERUSER'root'@'localhost'IDENTIFIEDBY'newpassword';QueryOK,0rowsaffected(0.00sec)mysql>exitBye

    7 安装完毕

    至此,使用在CentOS7中使用YUM方法安装MySQL5.7.10数据库完毕。如下所示,可以使用新的root密码登陆MySQL了。

    [root@typecodes~]#mysql-uroot-ppasswordmysql:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis3Serverversion:5.7.10MySQLCommunityServer(GPL)Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>usemysql;ReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedmysql>showdatabases;+--------------------+|Database|+--------------------+|information_schema||mysql||performance_schema||sys|+--------------------+4rowsinset(0.00sec)mysql>clearmysql>exitBye[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.noarchupdate2017.04.1011:10

    使用上面的yum方法也可以安装目前mysql官网上最新的版本mysql5.7.18。只要替换小节2中rmp包的版本即可,后续操作步骤不变。

    wget-i-chttp://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    centos7.3 安装mysql5.7.18的示例.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载