昨天幫朋友安裝了個lnmp的集成環境,可是部署程序後,發現怎麼都不行,試了好多種方式,發現都連不上mysql,因而就寫了個conn mysql的例子,發現報了上面這個錯誤,記錄下如何結局,防止下次找不到。php
1:使用phpinfo(),找到mysql.default_socket‘, ‘mysqli.default_socket‘, andmysql
‘pdo_mysql.default_socket‘. 記住這個值; 這個是 PHP 嘗試鏈接mysql的路徑。sql
2:個人值都是null,很奇怪,估計是之前我這兒安裝過一個mysql,形成了衝突,致使此次的安裝中間出現了錯誤。app
3:查看當前msyql的socket路徑socket
mysql> status -------------- mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrapper Connection id: 12 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.5.36-log Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /phpstudy/data/mysql.sock Uptime: 15 hours 56 min 0 sec
4:在phpinfo頁面找到php.ini的路徑,修改以上三個值爲UNIX socketcode