• centos7 搭建 mysql8


    记录centos搭建mysql遇到的坑

    1.  直接用centos 的yum命令进行安装,发现找不到 mysql-server,于是下载 rpm文件进行后在进行安装,具体可参考官网 https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

    2. mysql服务端安装成功,并从本地启动后,登陆不上。

        正常来说 mysql(8版本) 第一次 启动后,会在  /var/log/mysqld.log  记录一个 root 对应的临时密码  , 使用此密码通过 mysql -uroot -p"临时密码" 可登陆到mysql。

     临时密码可以通过 grep 'temporary password' /var/log/mysqld.log 这个命令查看到

        如果发现  /var/log/mysqld.log 文件为空或者无密码 。  可以在 /etc/my.cnf 文件的第二行插入 skip-grant-tables ,文件内容大致如下:

    [mysqld]
    #skip-grant-tables    -- 这一行表示可以不输入密码直接登入 mysql
    #skip-networking      -- 这一行表示本机运行,外部无法连接
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    # Settings user and group are ignored when systemd is used.
    # If you need to run mysqld under a different user or group,
    # customize your systemd unit file for mariadb according to the
    # instructions in http://fedoraproject.org/wiki/Systemd
    
    [mysqld_safe]
    log-error=/var/log/mariadb/mariadb.log
    pid-file=/var/run/mariadb/mariadb.pid
    
    #
    # include all files from the config directory
    #
    !includedir /etc/my.cnf.d
    
    default-character-set=utf8
    View Code

       这时,你已经可以登入mysql了,你还需要做的是 修改root密码,并新建普通用户,设置其可远程登陆。

       首先,设置 root 密码为空  ALTER USER 'root'@'localhost' IDENTIFIED BY '';  或者 直接 update mysql.user set authentication_string = '' where user = 'root' and host = 'localhost';

       接着先将  /etc/my.cnf  文件中的  skip-grant-tables 注释掉 , 并重启服务  service restart mysqld ,  使用  mysql -uroot -p'' 登陆mysql

      登陆mysql后你就可以修改 root 用户的密码了,使用命令   ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd'; 设置密码   [ 这里千万不要直接 update 设置密码 ]   。

    如果你不想设置复杂的密码,但是它一直报你的密码,你可以:
    SHOW VARIABLES LIKE 'validate_password%';
    +--------------------------------------+--------+
    | Variable_name                        | Value  |
    +--------------------------------------+--------+
    | validate_password.check_user_name    | ON     |
    | validate_password.dictionary_file    |        |
    | validate_password.length             | 8      |
    | validate_password.mixed_case_count   | 1      |
    | validate_password.number_count       | 1      |
    | validate_password.policy             | MEDIUM |
    | validate_password.special_char_count | 1      |
    +--------------------------------------+--------+
    其中 validate_password.policy 常量代表的是密码等级,0是low
           validate_password.length 常量代表的是密码长度 
    通过 set global validate_password_length=1; 来设置,
    View Code

      密码改完了, CREATE USER 'username'@'host' IDENTIFIED BY 'password';  新建一个用户 ; 

      修改数据库外部可访问: update mysql.user set host = '%' where user = 'user' and host = 'host';   

     用户提权限: GRANT ALL ON *.* TO 'user'@'%';       最后需要对外开放mysql监听的端口,一般为 3306

     参考:

       

      

       

  • 相关阅读:
    希腊字母写法
    The ASP.NET MVC request processing line
    lambda aggregation
    UVA 10763 Foreign Exchange
    UVA 10624 Super Number
    UVA 10041 Vito's Family
    UVA 10340 All in All
    UVA 10026 Shoemaker's Problem
    HDU 3683 Gomoku
    UVA 11210 Chinese Mahjong
  • 原文地址:https://www.cnblogs.com/one-lightyear/p/9678340.html
Copyright © 2020-2023  润新知