• ADADADADAD

    Linux下安装MySQL5.7的步骤[ mysql数据库 ]

    mysql数据库 时间:2024-11-28 13:03:48

    作者:文/会员上传

    简介:

    本次将在Linux下通过yum安装MySQL,安装的版本为MySQL 5.7,官网中是最新版本8.0,在网上查了下,发现最新版本的yum源也包含了旧版本,而我们,只需要在安装时启用 5.7 的安装即可。本

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

    本次将在Linux下通过yum安装MySQL,安装的版本为MySQL 5.7,官网中是最新版本8.0,在网上查了下,发现最新版本的yum源也包含了旧版本,而我们,只需要在安装时启用 5.7 的安装即可。

    本人环境:CentOS 7.3 64位

      1.检查CentOS是否有系统自带的mysql

      yum list installed | grep mysql

      如果存在系统自带的mysql及依赖,则通过yum remove将其卸载

        2.在官网中获取yum源

        这里获取到的是最新版本的下载地址:https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

          3.CentOS中下载rpm包,并安装本地mysql源

          下载rpm包:wgethttps://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm--no-check-certificate
          安装mysql源:yum localinstall mysql80-community-release-el7-3.noarch.rpm

          通过yum localinstall安装mysql源,可以帮助我们解决本地rpm包的依赖问题。

          最后,验证是否安装成功:yum repolist all | grep mysql

            4.修改默认安装版本为5.7

            从上面的图片,我们可以看到,默认是MySQL 8.0可用,我们若想安装MySQL 5.7,则需启用5.7。接下来通过直接修改配置文件来设置启用。

            vim /etc/yum.repos.d/mysql-community.repo

            输入上面的命令,在编辑界面,先输入i进入编辑模式,将8.0的enabled设置为0,将5.7的enabled设置为1,如下:

            接着按Esc退出编辑模式,最后输入:wq保存并退出。

            再次输入命令:yum repolist all | grep mysql,可以看到8.0已被禁用,而5.7是启用的。

              5.安装MySQL

              yum install mysql-community-server

              输入上面命令,进行安装即可。

              点我复制[root@wintestmysql]#yuminstallmysql-community-serverLoadedplugins:fastestmirrorLoadingmirrorspeedsfromcachedhostfileResolvingDependencies-->Runningtransactioncheck--->Packagemysql-community-server.x86_640:5.7.27-1.el7willbeinstalled-->ProcessingDependency:mysql-community-common(x86-64)=5.7.27-1.el7forpackage:mysql-community-server-5.7.27-1.el7.x86_64-->ProcessingDependency:mysql-community-client(x86-64)>=5.7.9forpackage:mysql-community-server-5.7.27-1.el7.x86_64-->ProcessingDependency:libaio.so.1(LIBAIO_0.4)(64bit)forpackage:mysql-community-server-5.7.27-1.el7.x86_64-->ProcessingDependency:libaio.so.1(LIBAIO_0.1)(64bit)forpackage:mysql-community-server-5.7.27-1.el7.x86_64-->ProcessingDependency:libaio.so.1()(64bit)forpackage:mysql-community-server-5.7.27-1.el7.x86_64-->Runningtransactioncheck--->Packagelibaio.x86_640:0.3.109-13.el7willbeinstalled--->Packagemysql-community-client.x86_640:5.7.27-1.el7willbeinstalled-->ProcessingDependency:mysql-community-libs(x86-64)>=5.7.9forpackage:mysql-community-client-5.7.27-1.el7.x86_64--->Packagemysql-community-common.x86_640:5.7.27-1.el7willbeinstalled-->Runningtransactioncheck--->Packagemariadb-libs.x86_641:5.5.52-1.el7willbeobsoleted-->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.27-1.el7willbeobsoleting-->Runningtransactioncheck--->Packagemysql-community-libs-compat.x86_640:5.7.27-1.el7willbeobsoleting--->Packagepostfix.x86_642:2.10.1-6.el7willbeupdated--->Packagepostfix.x86_642:2.10.1-7.el7willbeanupdate-->FinishedDependencyResolutionDependenciesResolved====================================================================================PackageArchVersionRepositorySize====================================================================================Installing:mysql-community-libsx86_645.7.27-1.el7mysql57-community2.2Mreplacingmariadb-libs.x86_641:5.5.52-1.el7mysql-community-libs-compatx86_645.7.27-1.el7mysql57-community2.0Mreplacingmariadb-libs.x86_641:5.5.52-1.el7mysql-community-serverx86_645.7.27-1.el7mysql57-community165MInstallingfordependencies:libaiox86_640.3.109-13.el7base24kmysql-community-clientx86_645.7.27-1.el7mysql57-community24Mmysql-community-commonx86_645.7.27-1.el7mysql57-community275kUpdatingfordependencies:postfixx86_642:2.10.1-7.el7base2.4MTransactionSummary====================================================================================Install3Packages(+3Dependentpackages)Upgrade(1Dependentpackage)Totaldownloadsize:197MIsthisok[y/d/N]:yDownloadingpackages:DeltaRPMsdisabledbecause/usr/bin/applydeltarpmnotinstalled.(1/7):libaio-0.3.109-13.el7.x86_64.rpm|24kB00:00:00warning:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.27-1.el7.x86_64.rpm:HeaderV3DSA/SHA1Signature,keyID5072e1f5:NOKEYPublickeyformysql-community-common-5.7.27-1.el7.x86_64.rpmisnotinstalled(2/7):mysql-community-common-5.7.27-1.el7.x86_64.rpm|275kB00:00:01(3/7):mysql-community-libs-5.7.27-1.el7.x86_64.rpm|2.2MB00:00:01(4/7):mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm|2.0MB00:00:01(5/7):postfix-2.10.1-7.el7.x86_64.rpm|2.4MB00:00:00(6/7):mysql-community-client-5.7.27-1.el7.x86_64.rpm|24MB00:00:34(7/7):mysql-community-server-5.7.27-1.el7.x86_64.rpm|165MB00:00:52------------------------------------------------------------------------------------Total3.5MB/s|197MB00:56Retrievingkeyfromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlImportingGPGkey0x5072E1F5:Userid:"MySQLReleaseEngineering<mysql-build@oss.oracle.com>"Fingerprint:a4a9406876fcbd3c456770c88c718d3b5072e1f5Package:mysql80-community-release-el7-3.noarch(installed)From:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlIsthisok[y/N]:yRunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionInstalling:mysql-community-common-5.7.27-1.el7.x86_641/9Installing:mysql-community-libs-5.7.27-1.el7.x86_642/9Installing:mysql-community-libs-compat-5.7.27-1.el7.x86_643/9Installing:mysql-community-client-5.7.27-1.el7.x86_644/9Installing:libaio-0.3.109-13.el7.x86_645/9Installing:mysql-community-server-5.7.27-1.el7.x86_646/9Updating:2:postfix-2.10.1-7.el7.x86_647/9Cleanup:2:postfix-2.10.1-6.el7.x86_648/9Erasing:1:mariadb-libs-5.5.52-1.el7.x86_649/9Verifying:mysql-community-libs-compat-5.7.27-1.el7.x86_641/9Verifying:mysql-community-common-5.7.27-1.el7.x86_642/9Verifying:mysql-community-libs-5.7.27-1.el7.x86_643/9Verifying:2:postfix-2.10.1-7.el7.x86_644/9Verifying:mysql-community-server-5.7.27-1.el7.x86_645/9Verifying:mysql-community-client-5.7.27-1.el7.x86_646/9Verifying:libaio-0.3.109-13.el7.x86_647/9Verifying:1:mariadb-libs-5.5.52-1.el7.x86_648/9Verifying:2:postfix-2.10.1-6.el7.x86_649/9Installed:mysql-community-libs.x86_640:5.7.27-1.el7mysql-community-libs-compat.x86_640:5.7.27-1.el7mysql-community-server.x86_640:5.7.27-1.el7DependencyInstalled:libaio.x86_640:0.3.109-13.el7mysql-community-client.x86_640:5.7.27-1.el7mysql-community-common.x86_640:5.7.27-1.el7DependencyUpdated:postfix.x86_642:2.10.1-7.el7Replaced:mariadb-libs.x86_641:5.5.52-1.el7Complete!

                6.启用MySQL

                在CentOS 6中,我们一般通过service mysqld start来启动mysql,在CentOS 7中,如果直接输入service mysqld start,则会出现以下信息:

                这是因为 CentOS 7 下重启服务不再通过service操作,而是通过systemctl操作,因此我们可以输入命令:

                启动mysql:systemctl start mysqld.service
                查看mysql状态:systemctl status mysqld.service

                  7.登录mysql

                  mysql -u root -p

                  在要求输入密码时,因为mysql 5.7的初始密码不是空,直接按回车键不能成功登录,因此需先找到初始密码,才能登录。

                  grep 'temporary password' /var/log/mysqld.log

                  如上,最后的内容就是初始密码。

                  再次登录,输入初始密码,即可成功登录。

                  第一次登录成功后,发现不能执行操作,同时提示让修改密码。

                    8.修改登录密码

                    alter user root@localhost identified by '新密码'

                    这里,我想设置新密码为 123456,但出现了报错,这里的报错是mysql的密码策略问题,输入命令:show variables like 'validate_password%',查看 mysql 初始的密码策略,发现密码的最小长度为8,密码的验证强度等级为MEDIUM,可以修改一下密码策略:

                    设置密码的验证强度等级:set global validate_password_policy=LOW
                    设置密码的最小长度:set global validate_password_length=6

                    好了,这时我们再次执行修改密码的sql,便不会报错了。

                    最后通过flush privileges刷新权限,使当前操作立即生效,就大功告成了。

                    注意:最后这里,也可以不修改密码策略,只要自己设置的密码满足MySQL的原密码策略即可。

                    mysql 添加远程访问

                    第一种:mysql 5.0(两种方式)

                    一、

                    在命令窗口输入,mysql -u root -p 回车,并输入密码

                    执行 use mysql

                    执行下面句子,查看权限,root默认权限为localhost

                    select user,host from user;

                    更改root权限为%

                    update user set host = '%' where user = 'root';

                    刷新

                    flush privileges;

                    二、

                    在命令窗口输入,mysql -u root -p 回车,并输入密码

                    执行 use mysql

                    设置test为账户,密码为:ceshipwd,权限为%,所有人

                    grant all on *.* to 'test'@'%' identified by 'ceshipwd';

                    如果权限不设置为所有人,可设定固定访问IP如下:

                    grant all on *.* to 'test'@'111.111.111.111' identified by 'ceshipwd';

                    最后,刷新

                    flush privileges;

                    第一种:mysql 8.0以上(两种方式)

                    一、

                    在命令窗口输入,mysql -u root -p 回车,并输入密码

                    执行 use mysql

                    执行下面句子,查看权限,root默认权限为localhost

                    select user,host from user;

                    更改root权限为%

                    update user set host = '%' where user = 'root';

                    刷新

                    flush privileges;

                    二、

                    在命令窗口输入,mysql -u root -p 回车,并输入密码

                    执行 use mysql

                    设置test为账户,密码为:ceshipwd,权限为%,所有人

                    先建立账号:

                    create user 'test'@'%' identified with mysql_native_password by 'ceshipwd';

                    再添加账号权限

                    grant all on *.* to 'test'@'%';

                    如果权限不设置为所有人,可设定固定访问IP如下:

                    grant all on *.* to 'test'@'111.111.111.111';

                    最后,刷新

                    flush privileges;

                    三、

                    各版本修改密码的格式:

                    mysql5.0格式如下:

                    本地可以访问

                    alter user 'ceshi'@'localhost' identified by 'ceshipw';

                    所有都可以访问

                    alter user 'ceshi'@'%' identified by 'ceshipw';

                    mysql8.0以上格式如下:

                    本地可以访问

                    alter user 'ceshi'@'localhost' identifiedwith mysql_native_password by 'ceshipw';

                    所有都可以访问

                    alter user 'ceshi'@'%' identified with mysql_native_password by 'ceshipw';

                    *使用navicat连接mysql8.0数据库时,提示1251-client does not support authentication protocol requested by server;consider upgrading mysql client 解决办法:

                    进入数据库,更新一下认证格式usermysql;#下面方式是修改密码的格式,即可正常访问alteruser'ceshi'@'%'identifiedwithmysql_native_passwordby'ceshipw';flushprivileges;

    Linux下安装MySQL5.7的步骤.docx

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

    推荐度:

    下载
    热门标签: linuxmysql