Warning: mysql_connect(): No such file or directory 解決方案總結(作業系統: Mac)
說明:
1. 執行環境: Mac OS X 10.11.4 (Mac 已經自帶 Apache, PHP)
2. 相關資料夾:
/etc/apache2/ ##Apache 配置資料夾 /Library/WebServer/Documents/ ##Apache 預設站點 /usr/local/mysql-5.7.11-osx10.9-x86_64 ##mysql安裝路徑
/private/php.ini.default ##php的配置檔案: 如配置 mysql.sock
>>問題原因:
For some reason mysql on OS X gets the locations of the required socket file a bit wrong, but thankfully the solution is as simple as setting up a symbolic link.
You may have a socket (appearing as a zero length file) as /tmp/mysql.sock or /var/mysql/mysql.sock but 1 or more apps is looking in the other location for it.
大神解釋說: PHP 在 MySQL socket 方面, 預設的配置有問題. 那麼現在只要修改 PHP 的配置檔案, 配置正確的 MySQL socket 路徑就可以了.
>>解決方案:
1. 獲取當前 mysql.default_socket、mysqli.default_socket
建立一個 PHP 檔案, 顯示 phpinfo():
<?php echophpinfo();
用瀏覽器開啟:
在此頁面,找到mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket資訊:
2. 獲取 Mac MySQL socket 路徑
通過控制檯進入 MySQL, 輸入命令: STATUS, 查詢 UNIX socket 值
➜ / mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.11 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>
3. 這時候, 你對比mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket和通過MySQL UNIX socket發現不一樣, 這就是 mysql_connect(); 警告的原因: PHP 配置 mysql 有問題.
4. 重新配置 PHP, 開啟php.ini(預設位置是: /private/etc/php.ini )
cd /private/etc/
chmod +rwx php.ini ##修改檔案許可權
vim php.ini
之後修改mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 的值為: /tmp/mysql.sock
(一共修改三處,分別為:mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket)
注意:
若用 vim php.ini 開啟的檔案為空(我操作的時候, 就是這樣), 說明沒有 php.ini 這個檔案
這個時候, 你瀏覽 /etc/ 資料夾下, 會有 php.ini.default 檔案, 複製 php.ini.default 重新命名為 php.ini , 再用 vim 修改檔案內容
cd /private/etc/ cp php.ini.default php.ini ##複製 php.ini.default, 並且重新命名 chmod +rwx php.ini ##修改檔案許可權 vim php.ini
5,重啟apache
sudo apachectl restart ##重啟 apache
解決啦!
相關推薦
Warning: mysql_connect(): No such file or directory 解決方案總結(作業系統: Mac)
說明: 1. 執行環境: Mac OS X 10.11.4 (Mac 已經自帶 Apache, PHP) 2. 相關資料夾: /etc/apache2/ ##Apache 配置資料夾 /Library/WebServer/Documents/ ##Ap
解決MAC下PHP連接MYSQL錯誤Warning: mysql_connect(): No such file or directory in conn.php
命令 data hpu mar 找到 clas p s connect file 今天在mac上用php去連接mysql數據庫,出現了 mac PHP Warning: mysql_connect(): [2002] No such file...
MacBook下-bash: cd: /Applications/Android: No such file or directory解決方案
前言 當我想在Android studio的Terminal中敲相關gradlew命令時,一直報[bash: gradlew: command not found]錯誤,很是心塞,故翻閱一些相關資料解決此問題,所幸是成功了,在此做一下筆記
open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory 解決方案
方法一. yum安裝 yum install *rhsm* 方法二 執行命令: ① wget http:
windows10使用git報錯 fatal:open /dev/null or dup failed: No such file or directory解決方案或git bash here閃退
安裝好git之後,在命令列輸入git --version報錯 百度搜了很久全涼了,試
mac系統-PHP連線mysql資料報錯 No such file or directory解決方案
結合網路上提供的解決方案提供在mac下的詳細解決方案 1.找到/private/etc/php.ini檔案,並開啟並檢視檔案 ..... pdo_mysql.default_socket= ..... mysqli.default_socket = ..... 你會看到
redis安裝報錯No such file or directory解決方案
redis安裝報錯: c:\Redis>redis-server [10648] 11 May 16:46:30.046 # Warning: no config file specified,
fatal error:xxx.h no such file or directory 解決方案
編譯程式的時候遇到了找不到依賴包的問題,找了很多解決方案都沒有解決,最後摸索了很久才解決,把過程記錄下來方便以後用。 碰到這種問題,首先是要找有沒有可安裝的依賴包,命令為: apt-cache search xxx | grep dev 用dev過濾是因為有時候相關的安裝包
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory 解決辦法
object init ror 文件 module libmysql 找到 str 軟連接 >>> import MySQLdbTraceback (most recent call last): File "<stdin>", line
fatal error: Python.h: No such file or directory 解決
parrot python error pycrypto python.h [常見錯誤] fatal error: Python.h: No such file or directory環境場景系統: Parrot Linux軟件: 系統python默認版本2.7 PyCharm默認版本P
Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory解決方法
mouse 正是 from key int stripe 進程 成功 stack 今天用pdo連接mysql遇到一個奇怪的問題,host設為127.0.0.1可以連接成功,設為localhost就會報如下的錯誤: PHP Fatal error: Uncaught ex
numa.h:No such file or directory 解決方法
解決 clas issues -o log 方法 -s body num 參考: numa.h:No such file or directory numa.h:No such file or directory 解決方法 Ubuntu: $ apt-get install
PyCharm ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory 解決辦法
圖片 object shared 8.0 body har error err cto PyCharm ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or d
error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory解決
make scp AR object normal memcache window 2.0 HA 我是從其他服務器scp來的memcached(~~~整個文件夾的那種,windows用多了的後遺癥) 在準備運行 ./memcached -d -u root -l loca
Ubuntu下 fatal error: Python.h: No such file or directory 解決方法
error ID apt overflow AC python3 TE cto fat 參考: fatal error: Python.h: No such file or directory Ubuntu下 fatal error: Python.h: No such f
DataError: [-] Error: 2, No such file or directory解決你用Django寫項目使用Docker安裝FastDFS,測試的時候遇到這個問題
安裝 tor 執行 項目 數據 docker serve error -- DataError: [-] Error: 2, No such file or directory我已經解決了 是因為我安裝storage的時候docker run -dti --network=
nginx 啟動報錯“var/run/nginx/nginx.pid" no such file or directory解決方法
今天剛搭建的nginx伺服器啟動時,報錯“var/run/nginx/nginx.pid" no such file or directory,按照他的意思我在var/run/新建了一個資料夾nginx,重新啟動,啟動成功。 但是當我虛擬機
gcc編譯報錯 checking whether the C compiler works... no 中的 error trying to exec 'cc1': execvp: No such file or directory解決辦法
1 首先檢查報錯原因是execvp: No such file or directory 因此要將/etc/profile的export PATH指向gcc的lib路徑中的cc1檔案 例如我的cc1檔案在/usr/lib64/gcc/x86_64-suse-linux/4.8/ 則輸出 export P
php錯誤:Warning: mkdir(): No such file or directory
Warning: mkdir(): No such file or directory if(!is_dir(‘customimages/album/’.KaTeX parse error: Expected '}', got 'EOF' at end of input: …images/a
hdfs dfs -ls後出現No such file or directory解決
原因是因為-ls預設目錄是在hdfs檔案系統的/user/使用者名稱(使用者名稱就命令列@符號前面的那個東西),但是你的hdfs系統內沒有這個資料夾,所以會顯示No such file or directory。 所以你需要在hdfs檔案系統內建立 [email protected