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

执行结果如下:

--12T08::.6NZ mysqld_safe Logging to '/usr/local/mysql/data/lyqdeMacBook-Pro.local.err'.
--12T08::.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
Server version: 5.7. MySQL Community Server (GPL) Copyright (c) , , 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,  row affected,  warning (0.01 sec)
Rows matched: Changed: Warnings:

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

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

可能会遇到的问题

登录mysql

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

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

ERROR  (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,  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)的更多相关文章

  1. mysql登录报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    在MySQL登录时出现Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问 对于出现拒绝访问root用户的解决方案错 ...

  2. Ubuntu下MySQL报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    在Ubuntu下 想要登录mysql数据库 root@JD:~# mysql -uroot -p 报错 ERROR 1045 (28000): Access denied for user 'root ...

  3. Mysql修改root用户密码 For Mac 报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    环境 Mysql版本:5.7.12 操作系统:OSX 10.11 安装文件:.dmg文件 MySQL:mysql-5.7.12-osx10.11-x86_64.dmg(注意5.7跟之前的字段有些不同, ...

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

    1.关闭mysql   # service mysqld stop2.屏蔽权限   # mysqld_safe --skip-grant-table   屏幕出现: Starting demo fro ...

  5. MAC使用mysql报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    遇到这种错误,需要重置密码. Step1:停止mysql,命令如下: $ sudo service mysql stop 或者是 $ sudo /usr/local/mysql/support-fil ...

  6. yum 安装 Mysql error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 开启远程连接 修改登入密码 忘记root密码 配置防火墙规则 随手mark

    yum 安装 MYsql:        yum install mysql mysql-server mysql-devel -y 1.1 登入报错: ERROR 1045 (28000): Acc ...

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

    案例环境: 操作系统 :Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64 bit 数据库版本 : Mysql 5.6.19 64 bit ...

  8. 解决MySQL5.7在MAC下登录ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)问题

    问题描述 今天在MAC上安装完MYSQL后,MYSQL默认给分配了一个默认密码,但当自己在终端上使用默认密码登录的时候,总会提示一个授权失败的错误:ERROR 1045 (28000): Access ...

  9. Ubuntu下 MySQL的“ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)”

    今天闲来无事,在Ubuntu上掏鼓一下mysql.但尴尬的是,当我输入mysql -u root -p的时候,抛出了一个错误:ERROR 1045 (28000): Access denied for ...

随机推荐

  1. python3爬虫爬取猫眼电影TOP100(含详细爬取思路)

    待爬取的网页地址为https://maoyan.com/board/4,本次以requests.BeautifulSoup css selector为路线进行爬取,最终目的是把影片排名.图片.名称.演 ...

  2. python3开发进阶-Django框架中form的查看校验方法is_valid()的源码,自定义验证方法

    form表单的校验方法is_valid() 点开我们发现这个函数里面只有两个方法方法,最终返回True or False 我们点进.is_bound属性,里面判断传输的数据不是空和上传文件不是空 点进 ...

  3. 1.1(Spring学习笔记)Spring基础(BeanFactory、ApplicationContext 、依赖注入)

    1.准备工作 下载Spring:http://repo.spring.io/libs-release-local/org/springframework/spring/    选择需要下载的版本    ...

  4. KEIL3中出现的字符不对齐的情况解决办法

    写代码的时候我的keil3中会出现光标不对齐的情况,如下图: 看似光标在t后面,其实是在逗号后面,这是因为字体加粗导致的.解决办法: Edit->Configuration->colors ...

  5. JavaScript之链式结构序列化1

    一.概述 在JavaScript中,链式模式代码,太多太多,如下: if_else: if(...){ //TODO }else if(...){ //TODO }else{ //TODO } swi ...

  6. devexpress 经验笔记

    1.去除 GridView 头上的 "Drag a column header here to group by that column" -->  点击 Run Desig ...

  7. Android Studio打包:“APP_NAME" IS NOT TRANSLATED IN ZH, ZH_CN……..解决办法

    开始用Android Studio更新到2.0稳定版,调试的时候没啥问题,在打包的时候出现了"app_name" is not translated in zh, zh_CN….. ...

  8. css自动换行与不换行

    1.自动换行 div{ word-wrap: break-word; word-break: normal; } 2.不换行 div{ white-space:nowrap; } 3.浮动效果不换行 ...

  9. python安全编程

    ##入门 这将是第一个一系列关于python编程的博客文章.python是一门非常强大的语言,因为它有信息安全社区的支撑.这意味着很多工具都是由python编写并且可以在脚本中调用很多模块.使用模块的 ...

  10. C# SendMail 发送邮件

    最近因为用的发送邮件的地方,就查询了资料,总结以下几个方法 1.利用新浪邮箱发送 2.利用公司邮箱发送 3.利用CDO发送,这种方式要引用Interop.ADODB.dll(http://www.no ...