php的mysqli_connect函数显示 No such file or directory错误以及localhost换成127.0.0.1执行成功
Centos7环境-php7-MariaDB5.5.60
(新安装的php7,执行php -m 显示有mysqli模块,php.ini没有改其它)
测试代码为:
<?php
//~ echo date('Y-m-d H:i:s',time());
$link_id = mysqli_connect('localhost','root','');
if($link_id)
{
echo 'ok';
}
else
{
echo mysqli_connect_error();
}
?>
网页运行时显示 No such file or directory 错误
把参数 'localhost' 换成 ‘127.0.0.1’ 后 显示 ok,即执行成功!如果想使用 ‘localhost' 这个参数
如果是新安装的MariaDB,一定要先执行
mysql_secure_installation
根据提示安装完成之后,再运行上述代码正常情况下就运行成功了。如果还显示错误再参考下面
解决方法为:
找到 /etc/my.cnf 文件(我的是在这个位置,具体根据自己的机器)
找到这一行:

然后找到 /etc/php.ini
找到这一行:

默认情况下为空,把它修改为上述路径就可以了(不用加引号)
重新启动php-fpm
使用 ’localhost' 参数,刷新网页显示 'ok',即运行成功
参考:【故障】php链接mysql数据库,使用localhost一直显示错误,当使用127.0.0.1l链接正常,故障记录
php的mysqli_connect函数显示 No such file or directory错误以及localhost换成127.0.0.1执行成功的更多相关文章
- php 连接mysql 主机 localhost,显示 No such file or directory
打开 php.ini文件,找到这1行 mysql.default_socket 然后将它修改为 mysql.default_socket=/path/to/mysql.sock /path/to/my ...
- /etc/rc.d/init.d/iptables: No such file or directory 错误原因
注:本文转载自cnblogs:一天学点的文章</etc/rc.d/init.d/iptables: No such file or directory 错误原因> RedHat Enter ...
- mkdir()提示No such file or directory错误的解决方法
转自:http://www.02405.com/program/php/1692.html 在php中使用mkdir()方法创建文件夹时报错:No such file or directory,出错代 ...
- Linux运行shell脚本提示No such file or directory错误的解决办法
Linux执行.sh文件,提示No such file or directory的问题: 原因:在windows中写好shell脚本测试正常,但是上传到 Linux 上以脚本方式运行命令时提示No s ...
- python打包成.exe工具py2exe0-----No such file or directory错误
转自:http://justcoding.iteye.com/blog/900993 一.简介 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具, ...
- 执行Python "/bin/usr/python: bad interpreter: No such file or directory" 错误
今天在电脑上写了一个Python脚本,写好之后用ftp传上去,然后执行/var/www/cron.py,结果报错,/bin/usr/python: bad interpreter: No such f ...
- Mysql_connect报告”No such file or directory”错误的解决方法
写了个php脚本单独执行mysql_connect(),发现错误信息居然是“No such file or directory"! 首先确定是mysql_connect()和mysql_pc ...
- find: `./folder': No such file or directory 错误处理
这是我正在处理的目录的内容: misha@hp-laptop:~/work/c/5$ ls -l total 8 -rw-rw-r-- 1 misha misha 219 May 20 15:37 d ...
- 解决openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory错误
问题 在Centos7上编译安装openssl后,运行openssl version出现如下错误: openssl: error while loading shared libraries: lib ...
随机推荐
- Spring3实战第一章 Aop 切面 XML配置
刚看spring3实战书籍第一章 切面以前没有关注过 现在看到了 随手试验一下 AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Objec ...
- Mybatis源码解析优秀博文
最近阅读了许久的mybatis源码,小有所悟.同时也发现网上有许多优秀的mybatis源码讲解博文.本人打算把自己阅读过的.觉得不错的一些博文列出来.以此进一步加深对mybatis框架的理解.其实还有 ...
- 【 PostgreSQL】工作中常用SQL语句干货
接触gp数据库近一年的时间,语法上和其他数据库还是有些许不同,工作中常用的操作语句分享给大家! -- 建表语句 create table ods.ods_b_bill_m ( acct_month t ...
- Linux 下shell中exec解析
exec和source都属于bash内部命令(builtins commands),在bash下输入man exec或man source可以查看所有的内部命令信息. bash shell ...
- awk 截取某段时间的日志
好久没有截取nginx/haproxy 中 的日志了,竟有点不熟悉了. 记录一下,以免以后忘记. NGINX 日志格式: 192.168.1.26 - - [14/Sep/2017:16:48:42 ...
- August 15th 2017 Week 33rd Tuesday
Would rather have done a regret, do not miss the regret. 宁愿做过了后悔,也不要错过了后悔. Yesterday, I read several ...
- codeforces 666C Codeword
codeforces 666C Codeword 题意 q个询问,一种询问是给你一个字符串,还有一种是问长度为n的,包含当前字符串为子序列的字符串有多少个. 题解 容易写出式子,但是不好化简. 观察一 ...
- HTML 教程
HTML5 标准 超文本标记语言(英语:HyperText Markup Language,简称:HTML) 是一种用于创建网页的标准标记语言. 您可以使用 HTML 来建立自己的 WEB 站点,HT ...
- tcp通讯中socket套接字accept和listen的关系
今天看到一个文章,客户端的connect在服务端调用accept之前,突然想到这可以建立正常的连接么?以前从没细细的思考过listen accept connect之前的关系,带着疑问学习了一下,记录 ...
- ZOJ-3278 8G Island---二分第k大
题目链接: https://cn.vjudge.net/problem/ZOJ-3278 题目大意: 给出两个数列A和B,长度分别为N,M (1<=N, M<=10^5, 1<=Ai ...