connect to server at 'localhost' failed

来源:互联网 发布:淘宝消费者服务电话 编辑:程序博客网 时间:2024/05/10 18:24

原文地址 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 0
原创粉丝点击