您好,登錄后才能下訂單哦!
這篇文章主要介紹解決php與mysql連接不上的方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
php與mysql連接不上解決方法:
1、獲取當前 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 配置信息
建立一個 PHP 文件, 顯示 phpinfo():
用瀏覽器打開:
在此頁面,找到mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket信息:
2、獲取 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> STATUS -------------- mysql Ver 14.14 Distrib 5.7.11, for osx10.9 (x86_64) using EditLine wrapper Connection id: 8 Current database: Current user: root@localhost SSL: Not in use Current pager: less Using outfile: ‘‘ Using delimiter: ; Server version: 5.7.11 MySQL Community Server (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /tmp/mysql.sock Uptime: 8 days 15 hours 1 min 17 sec Threads: 2 Questions: 21 Slow queries: 0 Opens: 114 Flush tables: 1 Open tables: 0 Queries per second avg: 0.000 --------------
3、這時候, 你對比 mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 和 通過 MySQL UNIX socket 發現不一樣, 這就是 mysql_connect(); 警告的原因: PHP 配置 mysql 有問題.
4、重新配置 PHP, 打開php.ini修改mysql.default_socket、mysqli.default_socket、pdo_mysql.default_socket 的值為: /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket=/tmp/mysql.sock mysqli.default_socket=/tmp/mysql.sock
或者修改my.cnf的socket:
[client] socket=/tmp/mysql.sock [mysqld] socket=/tmp/mysql.sock
以上是解決php與mysql連接不上的方法的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。