打开mysql就是显示进程已完成,发现报错mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
上网搜索教程,没有一篇能完全按照步骤走下来,故记录一下操作过程。
第一步
打开系统偏好设置,关闭mysql的服务(Stop Mysql Serve);
第二步
打开终端,输入
$ cd /usr/local/mysql/bin
$ sudo su
然后命令行变成以sh-3.2#开头,接着输入命令
./mysqld_safe --skip-grant-tables &
以安全模式进入数据库中,执行成功会显示如下:
mysqld_safe Logging to '/usr/local/mysql/data/lyqdeMacBook-Pro.local.err'.
mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
第三步
新建一个终端,输入命令
/usr/local/mysql/bin/mysql
回车进入mysql,执行成功会显示如下:
Your MySQL connection id is 433
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> 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密码
mysql> update user set authentication_string=password('你的新密码') where Host='localhost' and User='root';
执行成功如下:
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 0 Warnings: 1
退出mysql
mysql> exit;
第四步
杀死mysqld_safe进程,重启mysql。