mac下连接MySQL出现mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

好几个月都没有更新博客了(惭愧惭愧0.0),最近一直在进行app的改版,推翻,改版...死循环,到现在还没上线,烦躁中...

还是先说说这两天在新电脑上连接MySQL出现的问题吧.

解决步骤:
  • 第一步:此时如果你的mysql正在运行中,先要停掉;


    mac下连接MySQL出现mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)_第1张图片
    image.png
  • 第二步: 在终端以管理员权限启动mysqld_safe
    sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables,输入管理员密码后会出现下面的信息

2018-03-26T13:44:43.6NZ mysqld_safe Logging to '/usr/local/mysql/data/zhousongdeMacBook-Air.local.err'.
2018-03-26T13:44:43.6NZ mysqld_safe Logging to '/usr/local/mysql/data/zhousongdeMacBook-Air.local.err'.
2018-03-26T13:44:43.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2018-03-26T13:46:25.6NZ mysqld_safe mysqld from pid file /usr/local/mysql/data/zhousongdeMacBook-Air.local.pid ended
  • 第三步:新建一个窗口,输入
    /usr/local/mysql/bin/mysql -u root -p 输入MySQL密码,登录mysql,此时可能会出现Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    百度了各种方法均不好用,什么文件权限,日志过大导致mysql无法启动,最后找到这样一行命令: sudo chown -R mysql /usr/local/mysql/data,此时也许输入在设置中或者命令行中启动mysql都没有效果,重启电脑,然后mysql就能启动了.重新在终端输入 /usr/local/mysql/bin/mysql -u root -p,输入MySQL密码这时就能登录mysql了

    mac下连接MySQL出现mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)_第2张图片
    image.png

  • 第四步: 继续输入 use mysql

    image.png

    然后更新root密码
    update user set authentication_string=password('root') where Host='localhost' and User='root';
    结果为:
    Query OK, 1 row affected, 1 warning (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 1
    退出mysql(执行sql语句:exit)
    此时用Navicate Premium连接mysql,测试连接成功

你可能感兴趣的:(mac下连接MySQL出现mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO))