当前位置:Gxlcms > 数据库问题 > centos安装LAMP环境时访问本地MYSQL数据库错误

centos安装LAMP环境时访问本地MYSQL数据库错误

时间:2021-07-01 10:21:17 帮助过:3人阅读


其实就是说UNIX系统需要将localhost 这个地址进行转换的文件

解决的方法其他有三个

There are a few ways to solve this problem.

  1. You can just use TCP/IP instead of the Unix socket. You would do this by using 127.0.0.1instead of localhost when you connect. The Unix socket might by faster and safer to use, though.

  2. You can change the socket in php.ini: open the MySQL configuration file my.cnf to find where MySQL creates the socket, and set PHP‘s mysqli.default_socket to that path. On my system it‘s /var/run/mysqld/mysqld.sock.

  3. Configure the socket directly in the PHP script when opening the connection. For example:

    $db = new MySQLi(‘localhost‘, ‘kamil‘, ‘***‘, ‘‘, 0, 
                                  ‘/var/run/mysqld/mysqld.sock‘)

1、修改连接文件中localhost 为127.0.0.1

2、查看my.cnf文件中sock文件的位子,并赋值到php.ini:文件中的mysqli.default_socket去

3、PHP语言直接多一个参数指向sock文件位置。


本文出自 “1000空间” 博客,请务必保留此出处http://3609884.blog.51cto.com/3599884/1828364

centos安装LAMP环境时访问本地MYSQL数据库错误

标签:mysql   php   服务器   

人气教程排行