美文网首页
CentOS安装MySQL的步骤

CentOS安装MySQL的步骤

作者: 威威dett | 来源:发表于2019-03-14 17:17 被阅读0次

    1、官方安装文档

    http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

    2、下载 Mysql yum包,官方链接,可自行选择版本

    http://dev.mysql.com/downloads/repo/yum/

    下载到本地再上传到服务器,或者使用wget 直接下载

    wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
    

    3、安转软件源

    mysql57-community-release-el7-10.noarch.rpm 替换为你下载的rpm名

    sudo rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
    

    4、安装mysql服务端(这里可能要很久,网速不好的话)

     yum install  -y  mysql-community-server
    

    5、启动mysql

    service mysqld start
    systemctl start mysqld.service
    

    6、接着检查mysql 的运行状态

    service mysqld status
    

    之后与如下提示,说明启动成功了

    [root@localhost Desktop]# service mysqld status
    Redirecting to /bin/systemctl status  mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since Wed 2019-03-13 00:37:57 PDT; 37s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 10476 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 10395 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 10479 (mysqld)
       CGroup: /system.slice/mysqld.service
               └─10479 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/my...
    
    Mar 13 00:37:53 localhost.localdomain systemd[1]: Starting MySQL Server...
    Mar 13 00:37:57 localhost.localdomain systemd[1]: Started MySQL Server.
    

    7、修改临时密码

    Mysql5.7默认安装之后root是有密码的。

    7.1 获取MySQL的临时密码

    为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。
    只有启动过一次mysql才可以查看临时密码

    如果之前安装过MySQL则这里可能会有多个密码,用最后一个,注意这个密码输入时是可以粘贴的
    
    grep 'temporary password' /var/log/mysqld.log
    

    如:

    [root@localhost Desktop]# grep 'temporary password' /var/log/mysqld.log
    2019-03-13T07:37:54.834875Z 1 [Note] A temporary password is generated for root@localhost: Z5j&8Bv>&m9a
    

    我的密码就是:Z5j&8Bv>&m9a

    7.2 登陆并修改密码
    mysql -uroot -pZ5j&8Bv>&m9a
    

    修改密码(注意,登录后的操作后面都最好要有;结尾)

    ALTER USER 'root'@'localhost' IDENTIFIED BY '111111';
    

    如果密码设置太简单出现以下的提示如下:

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '111111';
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    

    如何解决ERROR 1819 (HY000): Your password does not satisfy the current policy requirements呢?
    必须修改两个全局参数:
    首先,修改validate_password_policy参数的值

    mysql> set global validate_password_policy=0;
    

    再修改密码的长度

    set global validate_password_length=1;
    

    再次执行修改密码就可以了

    ALTER USER 'root'@'localhost' IDENTIFIED BY '111111';
    

    8、授权其他机器登陆或其他地方登录如:Navicat

    注意: 后面对密码一定不能错,需要根据具体的做修改

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;
    
    FLUSH  PRIVILEGES;
    
    参考地址:

    安装地址:
    https://www.cnblogs.com/silentdoer/articles/7258232.html

    Navicat远程连接mysql参考地址:
    https://blog.csdn.net/xudailong_blog/article/details/80559624
    https://blog.csdn.net/sinat_29821865/article/details/80982250
    https://www.cnblogs.com/pigbigbig/p/5768287.html

    相关文章

      网友评论

          本文标题:CentOS安装MySQL的步骤

          本文链接:https://www.haomeiwen.com/subject/bfucmqtx.html