V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
reid2017
V2EX  ›  MySQL

绝望, brew 安装 mariadb 无法重置密码

  •  
  •   reid2017 · 2019-07-23 21:49:03 +08:00 · 5055 次点击
    这是一个创建于 1731 天前的主题,其中的信息可能已经有所发展或是发生改变。
    搞了两晚,安装了四次,前两次 mysql,后两次 mariadb,同样的问题,以前的版本在 /usr/local/var/log 会有个 mysqld.log 文件,会有第一次启动的随机密码,现在最新 mac 系统用 brew 安装没有这个日志了,各种方法试了无数遍,奶奶的。。

    有大佬打救一下吗?
    12 条回复    2020-03-03 16:30:04 +08:00
    msg7086
        1
    msg7086  
       2019-07-23 22:01:23 +08:00 via Android
    直接无密码启动然后重置 root 密码不行吗?
    chinvo
        2
    chinvo  
       2019-07-23 22:01:48 +08:00
    如果有旧的数据库 data 文件,不会生成新密码

    很久没用过 brewed database 了,都是 docker + volume map
    reid2017
        4
    reid2017  
    OP
       2019-07-23 22:17:31 +08:00
    @msg7086 不行。。
    nguoidiqua
        5
    nguoidiqua  
       2019-07-23 22:34:06 +08:00
    新版 MySQL 或是 MariaDB 密码字段不是 password 了,改成 authentication_string 了,如果去重设 password 字段是没用的。(这个不一定,)

    UPDATE user SET authentication_string = password('your_password') WHERE User = 'your_username';

    如果你进都进不去,那是因为 user 的 plugin 字段 设定为 Unix_Socket 了,无法密码登录,只能 sudo mysql 强登,然后把这个 plugin 字段改成空值或者 mysql_native_password 才能用传统密码方式登入。

    update mysql.user set plugin='mysql_native_password' where user='your_username';

    update mysql.user set plugin='' where user='your_username';
    Immortal
        6
    Immortal  
       2019-07-23 22:42:34 +08:00
    以前被恶心过几次。。。
    然后选择了 docker 香
    reid2017
        7
    reid2017  
    OP
       2019-07-23 23:17:22 +08:00
    @nguoidiqua
    ERROR 1348 (HY000): Column 'authentication_string' is not updatable
    reid2017
        8
    reid2017  
    OP
       2019-07-23 23:18:39 +08:00
    ```

    MariaDB [mysql]> select host,user,password,authentication_string,plugin from user;
    +---------------+------+----------+-----------------------+-----------------------+
    | Host | User | Password | authentication_string | plugin |
    +---------------+------+----------+-----------------------+-----------------------+
    | localhost | root | invalid | invalid | mysql_native_password |
    | localhost | reid | invalid | invalid | mysql_native_password |
    | localhost | | | | |
    | reiddembp.lan | | | | |
    +---------------+------+----------+-----------------------+-----------------------+
    4 rows in set (0.001 sec)

    ```
    qfdk
        9
    qfdk  
       2019-07-23 23:37:47 +08:00 via iPhone
    docker 吧 https://blog.qfdk.me/post/docker%20 初始化 MySQL 数据库%20%2B%20phpmyadimin.html 给你个我的链接
    WispZhan
        10
    WispZhan  
       2019-07-23 23:43:27 +08:00
    别拿 brew 折腾这些东西。某些场景下 brew 一堆问题。
    ---
    直接拿二进制包手动装省事。
    nguoidiqua
        11
    nguoidiqua  
       2019-07-23 23:49:48 +08:00
    @reid2017

    你这错误我不知道什么原因,我新安装个了一个 MariaDB 10.3.15 试了下,前面的改法依然有效。

    我想你这个可能是自己改动了什么别的地方造成的,可以先 flush privileges 再试试或者重启下数据库再试试,实在不行清除配置文件重新安装下。

    或者试试

    ALTER USER 'your_username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';



    SET password for 'your_username'@'localhost' = PASSWORD('your_password');
    nguoidiqua
        12
    nguoidiqua  
       2020-03-03 16:30:04 +08:00
    搞笑,搜索搜到我自己以前的回答了。

    现在我自己新装的 MariaDB 是 10.4 版本,用 update 更新修改密码的时候也遇到 ERROR 1348。我想可能 brew 编译安装的版本更新比较快,当时就已经是 10.4。

    根据 MariaDB 官方的说明,10.4 版本的 mysql 库里面增加了一个 global_priv 表,限制了对 mysql 库进行 update 操作。

    所以要改密码只能用 ALTER USER 和 SET password 指令了,例如 #11 楼的两条指令。

    官方给了另外一钟修改指令:

    ALTER USER your_username@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("your_password");
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1169 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:22 · PVG 02:22 · LAX 11:22 · JFK 14:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.