1

Working with PDO Class I've got a problem with a PHP socket connection.

After searching, I looked at this link and couldn't find any appropriate answer for me.

I using macOS Sierra Version 10.12.6

I tried to get some information from mysql> show variables like '%sock%' but didn't get any result from mysql shell. I logged successfully.

Don't have any my.cnf file in my /etc folder.

This is the result I got from php -i | grep pdo:

pdo_mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock

I am not using Laravel.

I changed configuration in my php.ini file to pdo_mysql.default_socket=/var/mysql/mysql.sock, but it still does not work.

How can I connect PHP and MySQL working properly on same socket connection?

Mekudad
  • 11
  • 5
  • Look at `/etc/my.cnf`. In the `[mysqld]` section you can define a `socket=/var/mysql/mysql.sock` and restart the mysql service. The fact that `show variables like `'%sock%'` returned nothing suggests your mysqld may not be configured to open a local socket. Alternatively you might be able to connect via TCP to `127.0.0.1` instead of specifying `localhost` (for which mysql will use a socket) for your database connection. – Michael Berkowski Oct 09 '17 at 03:06
  • The second way i tried and i got the same result .. I can't find the /etc/my.cnf folder , in mine /etc folder on mac there is no such file 'my.cnf' . I do have the .cnf file in mine php /xamppfile/etc/my.cnf , do you mean file in that location ? – Mekudad Oct 09 '17 at 08:55
  • I found on mine XAMP/xamppfiles/etc/my.cnf [mysqld] section this configuration -> user = mysql port=3306 socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock .. Still not working .. What can be the problem ? – Mekudad Oct 09 '17 at 09:10

1 Answers1

0

I'll tell you what I had to do on my Ubuntu. I am using LAMPP

Stop MYSQL system

sudo service mysql stop

Uninstall apache from the system

sudo apt remove apache2

run lampp

sudo /opt/lampp/manager-linux-x64.run

I did not change default servers.

stop all servers click in Configure at MySQL Database open Conf File

I had to find my socket adress Cannot find mysql.sock /var/run/mysqld/mysqld.sock

Change the socket configuration

socket=/var/run/mysqld/mysqld.sock
Dharman
  • 30,962
  • 25
  • 85
  • 135