linux安装mysql5.7.*

安装5.7.x的mysql

一、安装5.7.x的mysql源

# yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

检查mysql源是否安装成功:

# yum repolist enabled | grep "mysql.*-community.*"

如果出现如下代码,则表示安装成功:

!mysql-connectors-community/x86_64 MySQL Connectors Community                 74
!mysql-tools-community/x86_64      MySQL Tools Community                      74
!mysql57-community/x86_64          MySQL 5.7 Community Server                307

二、安装mysql

源设置成功之后, 继续安装mysql 并启动, 加入开机自启动服务,并在命令行验证

  1. 安装mysql
    # yum intall mysql-community-server
    
  2. 启动mysql
    # service mysqld start
    
    检查mysql启动是否正常
    # service mysqld status 或者 ps -ef | grep mysql
    
  3. 设置mysqld服务开机自启动
    # systemctl enable mysqld.service
    
    检查mysqld开机自启动是否设置成功
    # systemctl list-dependencies | grep mysqld
    
    如果出现如下代码,则表示设置成功
    ● ├─mysqld.service
    

三、获取mysql随机密码并修改

查阅mysql的官方文档(文档在上面工具/原料里面有写),查询对应的随机密码, 这里说明一下mysql5.7以后的争强了安全机制, 所以使用yum安装,启动会系统会自动生成一个随机的密码.

  1. 查看mysql的随机密码

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

    如下所示:

    2019-01-08T06:09:08.020701Z 1 [Note] A temporary password is generated for root@localhost: PGsPJa.oB5Wd
    

    "PGsPJa.oB5Wd"就是自动生成的随机密码。

  2. 修改mysql密码

    # mysql -uroot -pPGsPJa.oB5Wd
    
    进入mysql之后,输入以下命令:
    
    use mysql
    
    update user set authentication_string=password('你想要的密码') where user='root';
    

    注意:①、5.7版本及之后,要求密码包含大小写字母+数字+特殊字符。

  3. 重置密码

    如果忘记密码,请不要慌。打开mysql的配置文件,路径是/etc/my.cnf,
    在[mysqld]里面加入以下代码:

    skip-grant-tables
    

    再重新启动mysql服务

    # service mysqld restart
    

    就是可以不用密码直接进入mysql

    # mysql -uroot -p
    进入之后,
    use mysql
    update user set authentication_string=password('你想要的密码') where user='root';
    

    到此mysql安装完成,接下来安装php7.

猜你喜欢

转载自blog.csdn.net/qq_34856247/article/details/86538615