您的位置:首页 > 数据库 > MySQL

mac mysql Access denied for user问题有效解决方法

2016-05-02 16:57 585 查看
可能有些读者在安装完 mysql 之后出现以下错误提示:
mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)这是 mysql 在 linux 系统下的一个小缺陷,未给出 root 密码,导致初次无法登陆。这里给出 mysql 密码修改的有效方案,该方案在5.7.12亲测有效:0) 在用户目录下输入以下命令:
touch bashrc
sudo chmod +w bashrc
sudo vi /etc/bashrc
在bashrc的末尾增加以下两个命令别名,便于快速使用mysql
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
1) 停止 mysql 服务
sudo /usr/local/mysql/support-files/mysql.server stop
2) 在安全模式下启动 mysql
sudo mysqld_safe --skip-grant-tables
3) 新建一个命令窗口(可在当前窗口下按快捷键command+N创建):
mysql -u root
4) 在命令窗口下修改命令
mysql > UPDATE mysql.user SET Password=PASSWORD('1234') WHERE User='root';[/code]
Query OK, 1 row affected, 1 warning (0.01 sec)Rows matched: 1  Changed: 1  Warnings: 1[/code]
如未成功请参看【补充】5)
mysql > FLUSH PRIVILEGES;
6) 新建命令窗口,用密码1234再尝试登陆
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.12 MySQL Community Server (GPL)
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.
看到上述信息,就表明成功用 root 登陆 mysql。【补充】也许不同版本 mysql.user 栏目名称会有不同,如果上述 4)命令报错:ERROR 1054 (42S22): Unknown column 'password' in 'field list'
那么就更改命令为:mysql> update mysql.user set authentication_string=password('1234') where user='root';[/code]

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: