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. 【转】jmeter入门教程- Jmeter教程及技巧汇总

    https://blog.csdn.net/zouxiongqqq/article/details/72843500

  2. 福州3中集训day5

    数论,zld神犇认为我们都学过数论的,讲了一波高端(入门?)操作,从扩展欧几里得开始,同余方程诸如此类,早晚得重修.连课件都没,拿着画图讲了一上午 sro_zld_orz 具体内容都记在本上. 还是说 ...

  3. hdu6059( Trie )

    hdu6059 题意 给定数组 \(A\) ,问有多少对下标 \((i, j, k)\) 满足 \(i < j < k\) 且 \((A[i] \ xor \ A[j]) < (A[ ...

  4. 谜题27:变幻莫测的i值

    与谜题26中的程序一样,下面的程序也包含了一个记录在终止前有多少次迭代的循环.与那个程序不同的是,这个程序使用的是左移操作符(<<).你的任务照旧是要指出这个程序将打印什么.当你阅读这个程 ...

  5. c++基础学习之string

    //学习使用string类 2013-10-18 lingc #include <iostream> #include <string>//include this head ...

  6. []ARC099

    C:普及组难度的题 D:令$S(n)$表示$n$的数位和,一个数$n$是Snuke number当且仅当对所有$m\gt n$有$\frac n{S(n)}\leq\frac m{S(m)}$,求出前 ...

  7. 【动态规划】【spfa】【最短路】bzoj1003 [ZJOI2006]物流运输trans

    预处理cost[a][b] 表示第a天到第b天用同一条线路的成本. 具体转移看代码. #include<cstdio> #include<algorithm> #include ...

  8. RequireJS 2.0初探

    就在前天晚上RequireJS发布了一个大版本,直接从version1.0.8升级到了2.0.随后的几小时James Burke又迅速的将版本调整为2.0.1,当然其配套的打包压缩工具r.js也同时升 ...

  9. <摘录>Linux下动态共享库加载时的搜索路径详解

    对动态库的实际应用还不太熟悉的读者可能曾经遇到过类似“error while loading shared libraries”这样的错误,这是典型的因为需要的动态库不在动态链接器ld.so的搜索路径 ...

  10. winform treeview 绑定文件夹和文件

    转载:http://www.cnblogs.com/zhbsh/archive/2011/05/26/2057733.html #region treeview 绑定文件夹和文件 /// <su ...