• mac下mysql 1045 (28000): Access denied for user 'root'@'localhost' (using password:


    新入了mac pro,安装好mysql后,用终端进入mysql遇到个问题: 1045 (28000): Access denied for user 'root'@'localhost' (using password: N

    讲道理,我还设密码呢,但是第一次进来就报错,goo了一下大概原因可能是mysql创建的时候给自动分配了密码。

    不管分配没分配密码,反正一般的解决方法就是:先跳过验证,再重设密码。

    具体步骤:

    1. 先关闭MySQL服务;
    执行

    sudo /usr/local/mysql/support-files/mysql.server stop

    或者在系统偏好设置中关闭MySQL服务(如果电脑有设置密码的,此处会要求输入计算机密码)

    2.去mysql文件夹里设置跳过验证(3步)

    先进入mysql文件夹:
    cd /usr/local/mysql/bin/
    设置权限,如果电脑有设置密码(开机和解锁计算机时要求输入的那个密码),在输入此句后会要求输入密码。输入密码后按回车确认
    sudo su
    跳过验证
    ./mysqld_safe --skip-grant-tables &

    3.开始设置我们自己的新密码

    打开一个新的终端,输入

     /usr/local/mysql/bin/mysql -u root -p

    然后会要求输入密码,因为此时根本没有密码,所以直接点确认,显示以下信息表示成功进入mysql(与windows系统一样)

    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 20
    Server version: 5.7.11
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> 

    现在设置新密码,注意要打引号:

    UPDATE mysql.user SET authentication_string=PASSWORD('cc77') where User='root';

    回车确认,显示以下信息表示修改密码成功

    Query OK, 1 row affected, 1 warning (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 1

    然后刷新一下,让上述修改生效:

    flush privileges;

    刷新成功会显示以下信息:

    Query OK, 0 rows affected (0.01 sec)

    4.重启mysql,用新密码登录,可以登录成功了。但是进行其他mysql操作,会显示:

    ERROR 1820 (HY000) :You must reset your password using AlTER USER statement before executing this statement.

    意思是还要再重设一遍密码,直接输入:

    SET PASSWORD = PASSWORD('cc77');

    修改成功后,终端会显示:

    Query OK, 0 rows affected, 1 warning (0.01 sec)

    至此,修改密码彻底完成,可以做任何相关sql操作了

  • 相关阅读:
    每日一题(文化课)一题---------19/7/30
    XXXXX,这个域名
    CF1037E. Trips
    bzoj3124: [Sdoi2013]直径 树形dp two points
    luogu P3952 时间复杂度 模拟
    AGC016D
    CF444E. DZY Loves Planting
    模拟赛
    HDU 3949 XOR [线性基|高斯消元]
    博客搬家
  • 原文地址:https://www.cnblogs.com/hamsterPP/p/5274052.html
Copyright © 2020-2023  润新知