<span style="font-size: 14px;"><span style="color: #ff0000;">sudo</span> /usr/local/mysql/bin/mysqld_safe <span style="color: #999999;">--skip-grant-tables</span></span>
执行结果如下:
<span style="color: #800080;">2016</span>-<span style="color: #800080;">06</span>-12T08:<span style="color: #800080;">29</span>:<span style="color: #800080;">17</span>.6NZ mysqld_safe Logging to <span style="color: #800000;">‘</span><span style="color: #800000;">/usr/local/mysql/data/lyqdeMacBook-Pro.local.err</span><span style="color: #800000;">‘</span><span style="color: #000000;">. </span><span style="color: #800080;">2016</span>-<span style="color: #800080;">06</span>-12T08:<span style="color: #800080;">29</span>:<span style="color: #800080;">17</span>.6NZ mysqld_safe Starting mysqld daemon with databases <span style="color: #0000ff;">from</span> /usr/local/mysql/data
第三步:不要关闭当前的终端窗口,新建一个终端窗口,输入如下命令,回车登录mysql
/usr/local/mysql/bin/mysql
登录后,看到欢迎信息:
<span style="color: #000000;">Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id </span><span style="color: #0000ff;">is</span> <span style="color: #800080;">37</span><span style="color: #000000;"> Server version: </span><span style="color: #800080;">5.7</span>.<span style="color: #800080;">13</span><span style="color: #000000;"> MySQL Community Server (GPL) Copyright (c) </span><span style="color: #800080;">2000</span>, <span style="color: #800080;">2016</span>, Oracle and/<span style="color: #000000;">or its affiliates. All rights reserved. Oracle </span><span style="color: #0000ff;">is</span> a registered trademark of Oracle Corporation and/<span style="color: #000000;">or its affiliates. Other names may be trademarks of their respective owners. Type </span><span style="color: #800000;">‘</span><span style="color: #800000;">help;</span><span style="color: #800000;">‘</span> or <span style="color: #800000;">‘</span><span style="color: #800000;">h</span><span style="color: #800000;">‘</span> <span style="color: #0000ff;">for</span> help. Type <span style="color: #800000;">‘</span><span style="color: #800000;">c</span><span style="color: #800000;">‘</span><span style="color: #000000;"> to clear the current input statement. mysql</span>>
打开"mysql"这个数据库,SQL如下:
<span>mysql> </span>use mysql;
看到结果:
Reading table information <span style="color: #0000ff;">for</span><span style="color: #000000;"> completion of table and column names You can turn off </span><span style="color: #0000ff;">this</span> feature to <span style="color: #0000ff;">get</span> a quicker startup with -<span style="color: #000000;">A Database changed mysql</span>>
然后,更新root的密码,SQL如下:
mysql> update user <span style="color: #0000ff;">set</span> authentication_string=<span style="color: #ff0000;">password(‘root‘)</span> <span style="color: #0000ff;">where</span> Host=<span style="color: #800000;">‘</span><span style="color: #800000;">localhost</span><span style="color: #800000;">‘</span> and User=<span style="color: #800000;">‘</span><span style="color: #800000;">root</span><span style="color: #800000;">‘</span>;
注意:
①有的版本的mysql中,密码可能存储在password字段中,可以使用"describe user;"命令来查看下表结构再操作
②authentication_string的值一定通过password函数来计算(password(‘root‘))
执行结果如下:
Query OK, <span style="color: #800080;">1</span> row affected, <span style="color: #800080;">1</span> warning (<span style="color: #800080;">0.01</span><span style="color: #000000;"> sec) Rows matched: </span><span style="color: #800080;">1</span> Changed: <span style="color: #800080;">1</span> Warnings: <span style="color: #800080;">1</span>
退出mysql(执行sql语句:exit)
最后一步:将mysqld_safe进程杀死,重启mysqld。
可能会遇到的问题
登录mysql
/usr/local/mysql/bin/mysql -uroot -proot
这个时候,如果执行查询之类的操作,比如执行"show databases;",可能会有如下提示:
ERROR <span style="color: #800080;">1820</span> (HY000): You must reset your password <span style="color: #0000ff;">using</span> ALTER USER statement before executing <span style="color: #0000ff;">this</span> statement.
根据提示进行操作,输入如下SQL语句,这个语句的作用是修改root用户的口令为root:
mysql> alter user <span style="color: #800000;">‘</span><span style="color: #800000;">root</span><span style="color: #800000;">‘</span>@<span style="color: #800000;">‘</span><span style="color: #800000;">localhost</span><span style="color: #800000;">‘</span> identified by <span style="color: #800000;">‘</span><span style="color: #800000;">root</span><span style="color: #800000;">‘</span>;
结果:
Query OK, <span style="color: #800080;">0</span> 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)
标签:
本文系统来源:http://www.cnblogs.com/benbenzhu/p/5578162.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!