Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7967873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:59:20+00:00 2026-06-04T06:59:20+00:00

When i connect my database by a php script it shows Could not connect:

  • 0

When i connect my database by a php script it shows

Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

the username and password is right.

something of the my.cnf

[client]
#password       = your_password
port            = 3306
socket          = /data/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /data/mysql/mysql.sock
skip-external-locking

ps: i change it to socket = /var/lib/mysql/mysql.sock the php script still says “/var/lib/mysql/mysql.sock”?. then run

  mysqladmin -u root -p status

it shows

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!




service mysqld restart


mysqld: unrecognized service
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:59:21+00:00Added an answer on June 4, 2026 at 6:59 am

    Q: Does your my.conf still says “/var/lib/mysql/mysql.sock”?

    Q: Does the directory “/var/lib/mysql” exist?

    Q: Does your mysql user (or better, mysql group) have writer permission?

    If so, please try re-starting mysql and see what happens.

    ADDENDUM:

    One other thing to try is to create a mysql.sock and explicitly give it permissions:

    cd /var/lib
    mkdir mysql
    touch mysql/mysql.sock
    chown -R mysql:mysql mysql
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect to a mysql database within a php script. So
I am using the Database Backup script by David Walsh( http://davidwalsh.name/backup-mysql-database-php ) to backup
Scenario: I have got a client, php script and a MySQL database. I am
I have a php script which needs to connect to a database. The credentials
I have to perform a query similar to: <?php //....connect to database $old =
when I connect to my database I include('connect.php') the document to connect. Now I
Is that possible to connect mysql database between servers. I mean, lets say i
I have a CSV export script (enrdata_arch.php) which calls information from an existing database
In my application I'm querying a database via the use of a PHP script.
I am running a MySQL database with Mac OS X Lion Server. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.