mac系统中搭建apache+mysql+php的开发环境,安装mysql后,登录报错:mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

php新手在mac系统中搭建apache+mysql+php的开发环境(按照这篇博客来操作的:http://my.oschina.net/joanfen/blog/171109?fromerr=xvCsafCe),在安装配置mysql完毕后,登录mysql,报错:mac ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO),折腾很久,终于解决,随手记录下,备忘。

解决方法:

第一步:如果mysql服务正在进行,将之停止。

第二步:在终端中以管理员权限启动mysqld_safe,命令如下:

sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

执行结果如下:

2016-06-12T08:29:17.6NZ mysqld_safe Logging to ‘/usr/local/mysql/data/lyqdeMacBook-Pro.local.err‘.
2016-06-12T08:29:17.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

第三步:不要关闭当前的终端窗口,新建一个终端窗口,输入如下命令,回车登录mysql

/usr/local/mysql/bin/mysql

登录后,看到欢迎信息:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.7.13 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.

mysql> 

打开"mysql"这个数据库,SQL如下:

mysql> use mysql;

看到结果:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 

然后,更新root的密码,SQL如下:

mysql> update user set authentication_string=password(‘root‘) where Host=‘localhost‘ and User=‘root‘;

注意:

①有的版本的mysql中,密码可能存储在password字段中,可以使用"describe user;"命令来查看下表结构再操作

②authentication_string的值一定通过password函数来计算(password(‘root‘))

执行结果如下:

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

退出mysql(执行sql语句:exit)

最后一步:将mysqld_safe进程杀死,重启mysqld。

可能会遇到的问题

登录mysql

/usr/local/mysql/bin/mysql -uroot -proot

这个时候,如果执行查询之类的操作,比如执行"show databases;",可能会有如下提示:

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

根据提示进行操作,输入如下SQL语句,这个语句的作用是修改root用户的口令为root:

mysql> alter user ‘root‘@‘localhost‘ identified by ‘root‘;

结果:

Query OK, 0 rows affected

至此,问题解决。

参考:http://stackoverflow.com/questions/13480170/access-denied-for-mysql-error-1045

mac系统中搭建apache+mysql+php的开发环境,安装mysql后,登录报错:mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

时间: 2024-10-11 17:53:26

mac系统中搭建apache+mysql+php的开发环境,安装mysql后,登录报错:mac ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)的相关文章

mySQL报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

一般这个错误是由密码错误引起,解决的办法自然就是重置密码. 假设我们使用的是root账户. 1.步骤一:跳过MySQL的密码认证过程#vim /etc/my.cnf(注:windows下修改的是my.ini) 在文档内搜索mysqld定位到[mysqld]文本段:/mysqld(在vim编辑状态下直接输入该命令可搜索文本内容) 在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程 保存文档并退出:#:wq 2.步骤二:重启MySQL:/etc/init.

Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

最近操作mysql 5.6, 出现了以下问题. 分享,感谢原著: 案例环境: 操作系统 :Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64 bit 数据库版本 : Mysql 5.6.19 64 bit 案例介绍: 今 天开始学习mysql,遂先安装了Mysql 5.6.19 64bit 版本的数据库,结果安装成功了,但是使用root登录时遇到了ERROR 1045 (28000): Access denied for user '

Linux mysql 5.7: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

环境:mac10.12 来源:http://www.cnblogs.com/kerrycode/p/3861719.html 使用root登录时遇到了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)错误. 如下所示 [[email protected] tmp]# rpm -ivh MySQL-server-5.6.19-1.rhel5.x86_64.rpm Preparing..

Mysql 命令行启动问题ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Centos 刚装了mysql yum install mysql 安装成功了,安装最后要求输入了密码,也输入了,OK mysql -uroot -p 输入设置的密码 竟然报错了! ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YSE) 问朋友,他说初始密码是空的,可我命名设置了密码的阿. 密码留空 还是错误! ERROR 1045 (28000): Access denied for

Mac下解决mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Maybe updating the package the updater overwrote the root password. To restore it: Stop mysqld deamons. $ sudo service mysqld stop Go to mysql/bin directory $ cd /usr/bin Start a mysql deamon with this option: $ sudo mysqld_safe --skip-grant-tables O

mac mysql连接报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

找了半天 又是kill进程,又是改设置文件,又是重启电脑,都不管用 翻到stackoverflow上的解决方案,实施成功: 原文链接:https://stackoverflow.com/questions/13480170/access-denied-for-mysql-error-1045 To restore it: Stop mysqld deamons. $ sudo service mysqld stop Go to mysql/bin directory $ cd /usr/bin

解决mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)

1 现象 mysql -u root -p 错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)2 linux系统: 在配置文件my-default.cnf或my.cnf下 [mysqld]下添加skip-grant-tables:因为此方法无效,所以找到了以下方法 为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error

MySQL使用错误解决:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法: ⑴打开mysql中的my.ini(如果没有就将my-default.ini复制一份,并修改为my.ini): ⑵在[mysqld]下面空白行直接添加skip-grant-tables: ⑶重启mysql,在cmd页面输入mysql,按回车键即可. 注:这会使你的mysql无法设置密码,但对个人使用而言这岂不是更省了一步! MySQL使用错误解决:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using p

MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO

MySQL安装完server端和客户端后,登录Mysql时报错:[[email protected] MySQL 5.6.23-RMP]# mysqlERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[[email protected] MySQL 5.6.23-RMP]# service mysql startStarting MySQL.[