mysql链接不上,mysqli_connect提示File not found.解决方案
这个一般是由于nginx接收了请求,但是php没有准确响应,nginx返回:File not found.
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9005;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/../:/tmp/:/proc/";
include fastcgi_params;
}
上面的配置,主要注意需要注释root,然后SCRIPT_FILENAME可以使用非缺省的。
接下来如果操作mysql,像dede人才,明明连不上数据库,但是提示找不到用户名。
如果连不上数据库,直接排查:
使用正常的用户名和密码登录mysql:mysql -u用户名 -p
输入密码登录成功后输入STATUS
:
MariaDB [(none)]> STATUS
--------------
mysql Ver 15.1 Distrib 10.5.8-MariaDB, for Linux (x86_64) using readline 5.1
Connection id: 11
Current database:
Current user: dbuser@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.5.8-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 3 hours 36 min 59 sec
重点是:mysqli.default_socket =/var/lib/mysql/mysql.sock
然后修改php.ini文件,找到mysql.default_socket
和 mysqli.default_socket
上面两个都设置等于/var/lib/mysql/mysql.sock
保存重启php-fpm,搞定解决!
附原始的链接调测:
<?php
$conn = mysqli_connect('127.0.0.1','数据库用户','数据库密码');
if(!$conn)die('connError:'.mysql_error());
mysqli_select_db('数据库名',$conn);
$result = $conn->query('SELECT md5(123456)');
var_dump($result);
mysql_close($conn);