Mac mysql 忘記 root 密碼,phpmyadmin 登陸 No such file or directory 錯誤處理

20190629 mac 上安裝過 mysql 和 phpmyadmin以後,好久沒有使用(本機硬盤空間有限),今天想用的時候,死活輸入不對密碼了!

之前處理過的 mysql 忘記密碼處理,都是在 linux 上的

思路和處理方式是同樣的,可是具體操做起來,mac 上仍是不同!

一、參考

https://blog.csdn.net/liu_yanzhao/article/details/79427005php

開始沒有明白參考博客中 「 回車後 登陸管理員權限 sudo su 」 ,實際照着操做一下就明白了! 開始總覺得和過去的 sudo + 命令 方式同樣的! 如下就是個人錯誤過程mysql

$ sudo ./mysqld_safe --skip-grant-tables &linux

[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## 二、

$ sudo ./mysqlsql

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

二、個人過程記錄

請原諒!其實我都是照抄的!
  1. 查找個人 mysql 在哪裏 $ which mysql /usr/local/mysql/bin/mysqlmacos

  2. 進入 su $ sudo su sh-3.2#瀏覽器

    這是重點!後續實際上和 linux 上同樣了 後續命令都是在這個 # 方式下socket

  3. 禁止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
  4. sh-3.2# ./mysql 返回結果以下:.net

    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)

整個過程以下所示: 在這裏插入圖片描述

三、測試一下

再打開一個 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

四、 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 在這裏插入圖片描述

相關文章
相關標籤/搜索