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 su
sh-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 處
//i][‘host’] = ‘localhost’;
//by wzh 20190629
i][‘host’] = ‘127.0.0.1’;
//i][‘password’] = ‘’;
// by wz h20190629 123456
i][‘password’] = ‘123456’;
再次測試
http://127.0.0.1/phpMyAdmin-4.8.0.1-all-languages/index.php