connect to server at 'localhost' failed

原文地址 http://jingyan.baidu.com/article/915fc4149d529b51394b20cc.html

在Macbook Pro上安装好MySQL后,执行mysqladmin设置root帐号的密码时,报错

mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost' (using password: NO)'

怎么办?

connect to server at 'localhost' failed

工具/原料

  • mysql 5.7
  • macbook pro

方法/步骤

  1. 先停止MySQL服务

    打开“系统偏好设置”,选择“MySQL”,在打开的对话框中点击“Stop MySQL Server”

    connect to server at 'localhost' failed
    connect to server at 'localhost' failed
  2. 打开终端,输入命令:sudo /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 

    --skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。

    --skip-networking :跳过TCP/IP协议,只在本机访问(这个选项不是必须的。可以不用)

    connect to server at 'localhost' failed
  3. 保留开启mysqld_safe的终端,新建一个终端,输入命令:mysql

    此时我们就可以直接登录到MySQL服务了。

    connect to server at 'localhost' failed
  4. 查询MySQL的用户信息,输入SQL命令:

    select host,user,authentication_string from user;

    这一步骤熟悉的人可以跳过,在mysql 5.7以前的版本,密码列的英文名是password,但是在5.7版本改成了authentication_string,这点是需要注意的。

    connect to server at 'localhost' failed
  5. 我们只需要重置用户名为root的密码就可以,输入SQL命令:

    update user set authentication_string=PASSWORD('123456') where user='root' and host='localhost';

    connect to server at 'localhost' failed
  6. 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效

    connect to server at 'localhost' failed
  7. 重启MySQL服务,打开终端,输入命令:

    mysql -uroot -p

    输入刚设置好的密码就能成功登录

    connect to server at 'localhost' failed
    END
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值