20190629 mac 上安装过 mysql 和 phpmyadmin之后,很久没有使用(本机硬盘空间有限),今天想用的时候,死活输入不对密码了!
以前处理过的 mysql 忘记密码处理,都是在 linux 上的
思路和处理方式是一样的,但是具体操作起来,mac 上还是不一样!
1、参考
https://blog.csdn.net/liu_yanzhao/article/details/79427005
开始没有明白参考博客中 “ 回车后 登录管理员权限 sudo su ” ,实际照着操作一下就明白了!开始总以为和过去的 sudo + 命令 方式一样的!以下就是我的错误过程
$ sudo ./mysqld_safe --skip-grant-tables &
[1] 2070
dhbm-on-mac20180816:bin dhbm$ sudo ./mysqld_safe --skip-grant-tables &./mysql
[2] 2105
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[1]+ Stopped sudo ./mysqld_safe --skip-grant-tables## 2、
$ sudo ./mysql
Password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[4]+ Stopped sudo ./mysqld_safe --skip-grant-tables
2、我的过程记录
请原谅!其实我都是照抄的!
查找我的 mysql 在哪里$ which mysql/usr/local/mysql/bin/mysql
进入 su$ sudo sush-3.2#
这是重点!后续实际上和 linux 上一样了后续命令都是在这个 # 方式下
禁止mysql验证功能sh-3.2# ./mysqld_safe --skip-grant-tables &返回结果如下:
[1] 2141 sh-3.2# 2019-06-29T08:05:37.6NZ mysqld_safe Logging to '/usr/local/mysql-5.7.21-macos10.13-x86_64/data/dhbm-on-mac20180816.local.err'. 2019-06-29T08:05:38.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.21-macos10.13-x86_64/data
sh-3.2# ./mysql返回结果如下:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.21 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> 命令方式了!
5.mysql> FLUSH PRIVILEGES;返回结果如下:
Query OK, 0 rows affected (0.00 sec)
6.mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');返回结果如下:
Query OK, 0 rows affected, 1 warning (0.00 sec)
整个过程如下所示:
3、测试一下
再打开一个 Terminal$ mysql -u root -p返回结果如下:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 486
Server version: 5.7.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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
打开浏览器http://localhost/phpMyAdmin-4.8.0.1-all-languages/index.php输入 root /123456 之后还是错误啊!
mysqli_real_connect(): (HY000/2002): No such file or directory
4、 mysqli_real_connect(): (HY000/2002): No such file or directory 错误处理
正好我使用了 PHPStorm 打开了这个 phpmyadmin,目录结构一目了然如下图所示,直接复制一份 config.sample.php 到 config.inc.php命令行方式这里就不再列举了!不是重点!No such file or directory 指的是没有 config.inc.php 这个文件!修改以下 2 处//$cfg['Servers'][$i]['host'] = 'localhost';//by wzh 20190629$cfg['Servers'][$i]['host'] = '127.0.0.1';
//$cfg['Servers'][$i]['password'] = '';// by wz h20190629 123456$cfg['Servers'][$i]['password'] = '123456';
再次测试http://127.0.0.1/phpMyAdmin-4.8.0.1-all-languages/index.php