MySQL 5.6 - Database is running, but no Socket file - mysql

I am able to connect to mysql database and query it. But, I am NOT able to find the socket file.
$ps -ef|grep mysql
mysql 31408 30874 0 18:46 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/mysql/admin/ofile/TEST1.cnf
mysql 31959 31408 0 18:46 pts/1 00:00:01 /usr/sbin/mysqld --defaults- file=/mysql/admin/ofile/TEST1.cnf --basedir=/usr -- datadir=/mysql01data/TEST1/data --plugin-dir=/usr/lib64/mysql/plugin --log- error=/mysql/admin/TEST1/errors/mysqld_safe.err --pid- file=/mysql/admin/TEST1/run/mysqld_safe.pid
Here is my socket file entry in TEST1.cnf:
$ cat /mysql/admin/ofile/TEST1.cnf|grep sock
socket = /mysql/admin/TEST1/run/TEST1.sock
The corresponding directory only contains pid file. There is no socket file.
-sh-4.1$ cd /mysql/admin/TEST1/run
-sh-4.1$ ls -lrt
total 4
-rw-rw---- 1 mysql mysql 6 Apr 29 18:46 mysqld_safe.pid
This is the MySQL 5.6 version I installed through RPM's on RHEL 6.5. I have my old custom scripts which uses socket file to connect to the database.
So, I am wondering how I can use the socket file to connect to the database? Why the socket file is not created by default?

The socket file for a running instance of MySQL Server should be something that can be found with this shell command:
sudo lsof -a -U -p $(pgrep -d, -f /path/to/your/running/mysqld)
One possible cause of being unable to find the socket file would be if it had been deleted after the server was started. In that case the above command should work, and show something like (deleted) after the path.
That was my original assumption on this question... but here the issue was a configuration oversight. The "defaults file," commonly called my.cnf contains multiple sections. The [client] section configures client utilities, like mysql and mysqldump, while the [mysqld] section configures the server daemon. If the socket directive isn't in the appropriate section, the server (and/or client utilities) will look in the location compiled in by default, with /tmp/mysql.sock or /var/lib/mysql/mysql.sock being a couple of examples of common default locations.

Related

Installing Mysql on a VM under Alpine

I'm trying to install and use mysql on Alpine. I'm using Docker to generate a VM under Alpine.
My Dockerfile is really simple :
FROM alpine:3.11.3
CMD sh
Once I've run the image created (using docker build // docker run image_id), I install Mysql :
apk add --update --upgrade mysql mysql-client
Then, I install the database :
mysql_install_db
The problem is that once I've done that and I try to "mysql", the machine returns this :
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
And when I try to do "mysqld -u root", it returns me this problem :
2020-08-26 10:07:55 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2020-08-26 10:07:55 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2020-08-26 10:07:55 0 [ERROR] Can't start server : Bind on unix socket: No such file or directory
2020-08-26 10:07:55 0 [ERROR] Do you already have another mysqld server running on socket: /run/mysqld/mysqld.sock ?
2020-08-26 10:07:55 0 [ERROR] Aborting
I understood that the file mysqld.sock serves the server to discuss with the client. I tried to create the directory mysqld and then to create the file mysqld.sock but it doesn't work. It returns me the same error but with a different return value.
(ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (111)
At least, I don't want to use an existing image of mysql on Dockerhub.
Do anybody has an idea of what step is missing to make it work ?
Sorry if I'm not writing proper, I'm not a native english speaker.
I was able to successfully install and start mysql on an alpine container with these commands:
$ docker run -it --rm alpine:latest
/ # apk add mysql mysql-client
/ # mkdir /run/mysqld
/ # mysql_install_db
/ # mysqld -u root --data=./data &> /dev/null &
Testing connection:
/ # mysql -e "SELECT VERSION();"
+----------------+
| VERSION() |
+----------------+
| 10.6.4-MariaDB |
+----------------+

MySQL community server suddenly stopped working [duplicate]

My problem started off with me not being able to log in as root any more on my mysql install. I was attempting to run mysql without passwords turned on... but whenever I ran the command
# mysqld_safe --skip-grant-tables &
I would never get the prompt back. I was trying to follow these instructions to recover the password.
The screen just looks like this:
root#jj-SFF-PC:/usr/bin# mysqld_safe --skip-grant-tables
120816 11:40:53 mysqld_safe Logging to syslog.
120816 11:40:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
and I don't get a prompt to start typing the SQL commands to reset the password.
When I kill it by pressing CTRL + C, I get the following message:
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
If I retry the command and leave it long enough, I do get the following series of messages:
root#jj-SFF-PC:/run/mysqld# 120816 13:15:02 mysqld_safe Logging to syslog.
120816 13:15:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120816 13:16:42 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+ Done mysqld_safe --skip-grant-tables
root#jj-SFF-PC:/run/mysqld#
But then if I try to log in as root by doing:
# mysql -u root
I get the following error message:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I checked and /var/run/mysqld/mysqld.sock file doesn't not exist. The folder does, but not the file.
Also, I don't know if this helps or not, but I ran find / -name mysqld and it came up with:
/var/run/mysqld - folder
/usr/sbin/mysqld - file
/run/mysqld - folder
I don't know if this is normal or not. But I'm including this info just in case it helps.
I finally decided to uninstall and reinstall mysql.
apt-get remove mysql-server
apt-get remove mysql-client
apt-get remove mysql-common
apt-get remove phpmyadmin
After reinstalling all packages again in the same order as above, during the phpmyadmin install, I got the same error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
So I tried again to uninstall/reinstall. This time, after I uninstalled the packages, I also manually renamed all mysql files and directories to mysql.bad in their respective locations.
/var/lib/mysql
/var/lib/mysql/mysql
/var/log/mysql
/usr/lib/perl5/DBD/mysql
/usr/lib/perl5/auto/DBD/mysql
/usr/lib/mysql
/usr/bin/mysql
/usr/share/mysql
/usr/share/dbconfig-common/internal/mysql
/etc/init.d/mysql
/etc/apparmor.d/abstractions/mysql
/etc/mysql
Then I tried to reinstall mysql-server and mysql-client again. But I've noticed that it doesn't prompt me for a password. Isn't it supposed to ask for an admin password?
Try this command,
sudo service mysql start
To find all socket files on your system run:
sudo find / -type s
My Mysql server system had the socket open at /var/lib/mysql/mysql.sock
Once you find where the socket is being opened, add or edit the line to your /etc/my.cnf file with the path to the socket file:
socket=/var/lib/mysql/mysql.sock
Sometimes the system startup script that launched the command line executable specifies a flag --socket=path. This flag could override the my.cnf location, and that would result in a socket not being found where the my.cnf file indicates it should be. Then when you try to run the mysql command line client, it will read my.cnf to find the socket, but it will not find it since it deviates from where the server created one. So, Unless you care where the socket resides, just changing the my.cnf to match should work.
Then, stop the mysqld process. How you do this will vary by system.
If you're super user in the linux system, try one of the following if you don't know the specific method your Mysql setup uses:
service mysqld stop
/etc/init.d/mysqld stop
mysqladmin -u root -p shutdown
Some systems aren't setup to have an elegant way to stop mysql (or for some reason mysql doesn't respond) and you can force terminate mysql with either:
One step: pkill -9 mysqld
Two step (least preferred):
Find the process id of mysql with either pgrep mysql or ps aux | grep mysql | grep -v grep
Assuming the process id is 4969 terminate with kill -9 4969
After you do this you might want to look for a pid file in /var/run/mysqld/ and delete it
Make sure the permissions on your socket is such that whatever user mysqld is running as can read/write to it. An easy test is to open it up to full read/write and see if it still works:
chmod 777 /var/run/mysqld/mysqld.sock
If that fixes the issue, you can tailor the permissions and ownership of the socket as needed based on your security settings.
Also, the directory the socket resides in has to be reachable by the user running the mysqld process.
This error occurs due to multiple installations of mysql.
Run the command:
ps -A|grep mysql
Kill the process by using:
sudo pkill mysql
and then run command:
ps -A|grep mysqld
Also Kill this process by running:
sudo pkill mysqld
Now you are fully set just run the following commands:
service mysql restart
mysql -u root -p
Have very well working mysql again
The solution is way easier.
First, you have to locate(in Terminal with "sudo find / -type s") where your mysql.sock file is located. In my case it was in /opt/lampp/var/mysql/mysql.sock
Fire up Terminal and issue
sudo Nautilus
This starts your Files manager with super user privileges
From Nautilus navigate to where your mysql.sock file is located
Right click on the file and select Make Link
Rename the Link File to mysqld.sock then Right click on the file and Cut it
Go to /var/run and create a folder called mysqld and enter it
Now right click and Paste the Link File
Voila! You will now have a mysqld.sock file at /var/run/mysqld/mysqld.sock :)
Just Need to Start MySQL Service after installation:
For Ubuntu:
sudo service mysql start;
For CentOS or RHEL:
sudo service mysqld start;
There is a bug on Ubuntu with MySQL 5.6 and 5.7 where var/run/mysqld/ would disappear whenever MySQL service stopped or is rebooted. This prevents MySQL from running at all. Found this workaround, which isn't perfect, but at least it gets it running after stopping/reboot:
mkdir /var/run/mysqld/
chown mysqld /var/run/mysqld/
Make sure your inaccessible socket file path is same as '/var/run/mysqld/mysqld.sock', otherwise change the path as yours.
Stop the mysqld
$ sudo /etc/init.d/mysqld stop
If the process still runing;
$ sudo pkill -9 mysqld
Remove the mysql directory where socket going to create. For me it did not allowed to remove, so I had to forcefully remove.
$ sudo mkdir -p /var/run/mysqld
Set the ownership to the dirctory
$ sudo chown mysql:mysql /var/run/mysqld
Start mysql
$ sudo /etc/init.d/mysql start
Trying to connect mysql
$ sudo mysql -u dbuser -p
Okay just copy and paste these codes: This should be done in the terminal, inside a server, when your mysql database is not properly installed, and when you are getting this error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'.
Stop MySql
sudo /etc/init.d/mysqld stop
Restart it or start it
sudo /etc/init.d/mysqld restart or sudo /etc/init.d/mysqld start
Make a link like this and give it to the system
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
Run a secure installation which guides all the process you need to do to configure mysql
/usr/bin/mysql_secure_installation
I faced same error and found that it was due to upgradation of packages, So after restarting my system I resolved error.
I think due to sql libraries/ packages update that error occured, So try this if you are doing some upgrading :)
There is a lots of reason for this issue, but sometimes just restart the mysql server, it will fix the issue.
sudo service mysql restart
The answer of the user load step worked for me.
Sometimes is need edit the file in /etc/mysql/my.cnf add line to client
[client]
password = your_mysql_root_password
port = 3306
host = 127.0.0.1
socket = /var/lib/mysql/mysql.sock
Using XAMPP on ubuntu:
Create a folder called mysqld inside /var/run directory. You can accomplish that using the command sudo mkdir /var/run/mysqld.
Create a symbolic link to mysql.sock file that is created by the XAMPP server when it is started. You can use the command sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock.
Note: The mysql.sock file is created when the server is started and removed when the server is stopped, so sometimes the link you created might appear to be broken but it should work as long as you have started the server using either sudo /opt/lampp/lampp start or any other means.
Start the server if it's not already running and try executing your program again.
Good luck! I hope you'll get away with it this time.
I think your MySQL server has not started. So start the server using one of the following commands.
#services mysql start
or
#/etc/init.d/mysql start
Why getting this error
I received new updates of mysql libraries so i updated my Kubuntu OS after that getting these errors.
Commands i tried and how i fixed it.
MySql-server is running correctly but when i tried to connect its giving
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'.
I checked /var/run/mysqld/mysqld.sock'. this directory.
My files did not existed.
I also tried these commands to connect but did not worked for me.
mysql -h 127.0.0.1 -P 3306 -u root -p
sudo service mysql start
After wasting round about 2 hours i found the solution
sudo apt-get clean
sudo apt-get update
sudo apt-get upgrade -f
After that everything fixed for me.
*Error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
solutions
finally uninstall and reinstall mysql. **
sudo apt-get remove mysql-server
sudo apt-get remove mysql-client
sudo apt-get remove mysql-common
sudo apt-get remove phpmyadmin
then install again by
sudo apt-get install mysql-server-5.6
After this operation, 164 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y press YES for complete installations
......
.......
At last you will get these lines....
Setting up libhtml-template-perl (2.95-1) ...
Setting up mysql-common-5.6 (5.6.16-1~exp1) ...
Processing triggers for libc-bin (2.19-0ubuntu6)
Processing triggers for ureadahead (0.100.0-16) ...
And then
root#ubuntu1404:~# mysql -u root -p (for every password first u
should use )
Enter password:
Note :Entered password should be same as the installation time
password of mysql(like .root,system,admin,rahul etc...)
Then type
USE rahul_db(database name);
Thanks.**
Temporary Solution
Maybe someone facing this problem. I am using Mysql Workbench on Ubuntu 14 and got this error.
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect
Find your socket file by running sudo find / -type s, in my case it was /run/mysqld/mysqld.sock
So, I just created a link to this file in tmp directory.
sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
Please note that this is a temporary solution since the file created will be under /tmp. See other answers for a permanent solution.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
in /etc/my.cnf add this lines:
[client]
socket=/var/lib/mysql/mysql.sock <= this path should be also same as is[mysqld]
And restart the service with:
service mysql restart
this worked for me
This was mentioned a couple of times already, but this worked immediately for me:
service mysql restart
you can find mysqld.sock in /var/run/mysqld if you have already installed mysql-server
by sudo apt-get install mysql-server
I just had this problem on Ubuntu 14.10
Turns that mysql-server was no longer installed (somehow it had been removed) but I couldn't just install it because there were some broken packages and dependency issues/conflicts.
In the end I had to reinstall mysql
sudo apt-get remove mysql-client
sudo apt-get install mysql-server
I had the exactly same issue. After struggling for an hour, I found a way of correcting it without reinstalling mysql-common, mysql-client, mysql-server.
First of all, go to "/var/run/mysqld". You will find that the mysql.sock does not exist. Simply remove the entire mysqld directory and recreate it and provide it necessary privileges.
# rm -rf /var/run/mysqld && mkdir /var/run/mysqld && chown mysql /var/run/mysqld/
Now, Kill the mysql process in it's entirety. It might be possible that it will show you "waiting for page cleaner" on running "/etc/init.d/mysql status" command even after shutting down the service.
To completely close the service, use
# pkill -9 mysqld
Once the process is killed, try starting it again using
# /etc/init.d/mysql start
And you will see that it works good! And also there will be no issue in stopping it too.
In My case two mysqld processes were running..
killed the optional processs by using
pkill -9 mysqld
If you have a lot of databases and tables on your system, and if you have innodb_file_per_table set in my.cnf, then your mysql server might have run out of opened objects / files (or rather the descriptors for these objects)
Set a new max number with
open-files-limit = 2048
and restart mysql.
This approach might help when the socket is not created at all, but really this might not not be the real problem, there is an underlying problem.
My solution;
Ubuntu 18.04 (WSL)
/etc/mysql/my.cnf
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
/etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
I changed the port. It's worked for me. You can write another port. Example 3355
I am using XAMPP on Ubuntu. I found this error when connecting database through terminal. I solve it without any configuration because default socket file path in XAMPP is written in "/opt/lampp/etc/my.cnf" as following:
[client]
#password = your_password
port = 3306
socket = /opt/lampp/var/mysql/mysql.sock
now you can connect just by giving this socket path parameter with mysql command on terminal like:
mysql -u root --socket /opt/lampp/var/mysql/mysql.sock
and it's done without any configuration.
If you don't want to type socket path everytime, then go for changing default path in my.cnf by "/var/run/mysqld/mysqld.sock". Provide permissions and restart mysql server.
Edit:
Recently I've installed Ubuntu 20.04 and trying to install MySQL server but my system were crashing and not working at all. So I've just completely removed MySQL and installed MariaDB. Its working like a charm without any problems.
Changing the host to 127.0.0.1 worked for me.
Edit the file in /etc/mysql/my.cnf and add the below mentioned line to the section: client
[client]
port = 3306
host = 127.0.0.1
socket = /var/lib/mysql/mysql.sock
After you are done with it. Execute the following command.
sudo service mysql start
I had similar problem on a CentOS VPS. If MySQL won't start or keeps crashing right after it starts, try these steps:
1) Find my.cnf file (mine was located in /etc/my.cnf) and add the line:
innodb_force_recovery = X
replacing X with a number from 1 to 6, starting from 1 and then incrementing if MySQL won't start. Setting to 4, 5 or 6 can delete your data so be carefull and read http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html before.
2) Restart MySQL service. Only SELECT will run and that's normal at this point.
3) Dump all your databases/schemas with mysqldump one by one, do not compress the dumps because you'd have to uncompress them later anyway.
4) Move (or delete!) only the bd's directories inside /var/lib/mysql, preserving the individual files in the root.
5) Stop MySQL and then uncomment the line added in 1). Start MySQL.
6) Recover all bd's dumped in 3).
Good luck!
I uninstalled mysql in Ubuntu 16.04 https://askubuntu.com/questions/172514/how-do-i-uninstall-mysql
I reinstalled mysql
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04
This seemed to work.
First create dir /var/run/mysqld
with command:
mkdir -p /var/run/mysqld
then add rigths to the dir
chown mysql:mysql /var/run/mysqld
after this try
mysql -u root
You must install mysql-server
apt install mysql-server

Mysql with docker: Can't connect to local MySQL server through socket

I cannot use MySQL anymore in my Docker container:
root#mysql-container:/# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
mysqld is running:
root#mysql-spirit-ssl:/etc/mysql/conf.d# /etc/init.d/mysql start
[info] A MySQL Server is already started.
Trying to stop mysqld timed out:
root#mysql-container:/# /etc/init.d/mysql stop
............................................................[info] Attempt to shutdown MySQL Community Server 5.7.17 timed out.
So I tried to start using the mysqladmin way:
root#mysql-container:/# /usr/bin/mysqladmin --port=8889 -u root shutdown
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)'
So I checked that MySQL daemon is running:
root#mysql-container:/# ps -eax
PID TTY STAT TIME COMMAND
1 ? Ssl 0:01 mysqld
And that socket exists:
root#mysql-container:/# ls -l /var/run/mysqld/mysqld.sock
-rwxrwxrwx. 1 mysql mysql 0 Jan 4 10:12 /var/run/mysqld/mysqld.sock
I already tried to:
restart my Docker container
comment bind address in my.cnf and restart my Docker container
kill mysqld process => does not work, process is still listed by ps -eax
recreate my Docker container
restart Docker
restart the server
delete pid and sock files, and /etc/init.d/mysql start
Result of cat /var/log/mysql/error.log:
2018-02-27T15:27:35.966028Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2018-02-27T15:27:35.966061Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
However I cannot kill that mysqld process, either with pkill mysqld, kill -9 1 or initctl --system stop mysql.
Could this be related to Docker?
Remark: The MySQL daemon could not be killed because it was owned by Docker user systemd+ and it was the entry point of the container. Indeed mysqld was process with PID 1. This means that MySQL daemon could be restarted by simply restarting the Docker container, and that MySQL configuration could be modified in between.
I noticed in MySQL logs tail -f /var/log/mysql/error.log that a data recovery was triggered on daemon start due to an anomaly detected during internal log scan: the database was not closed properly. However the recovery could not repair the data and an intentional crash was performed. As a consequence, the container was restarted and so on. This infinite loop prevented mysqld to start and the socket to be used by the client mysql.
1) This configuration of /etc/mysql/conf.d/my.cnf enabled to skip the recovery:
[mysqld]
innodb_force_recovery=4
and to use mysql client with socket to dump important schemas and/or delete corrupted schemas.
Do not forget to remove this line from my.cnf after you're done!
2) Perfoming a mysql upgrade and repair could also have been beneficial:
docker exec -it mysql-container mysql_upgrade -u root -p --force
mysqlcheck -u root -p --auto-repair --check --all-databases
Restarting the Docker container is necessary after this step.
3) Also, deleting MySQL internal logs (that were scanned and triggered the recovery) was necessary:
cd /var/lib/mysql/mysql/
rm ibdata1 ib_logfile0 ib_logfile1
Now I can use MySQL again, from inside and outside the container.

OS X Mavericks: mysql socket defined in my.cnf, but not getting created

I'm trying to install mysql5 (the latest from Oracle, via .dmg) on OS X Mavericks. My /opt/local/my.cnf looks like this:
[client]
socket=/tmp/mysql.sock
[mysqld]
socket=/tmp/mysql.sock
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
When I try to connect, I get the following:
$ mysql5 -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
And there is no /tmp/mysql.sock file created.
Here's my /tmp dir:
$ ls -l /tmp
lrwxr-xr-x# 1 root wheel 11 Oct 24 08:31 /tmp -> private/tmp
I've also tried forcing the socket from the command line:
$ time sudo mysqld_safe5 --socket=/tmp/mysql.sock
Password:
131221 07:26:02 mysqld_safe Logging to '/opt/local/var/db/mysql5/Macintosh.local.err'.
131221 07:26:02 mysqld_safe Starting mysqld daemon with databases from /opt/local/var/db/mysql5
131221 07:17:26 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
I know it's reading the conf file because if I remove it, I get a different socket location when I attempt to connect:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)
But again, no luck. What do I need to do to get that socket created?
Change your /tmp folder to have permission for MySQL user. (chown mysql:mysql /tmp or chmod 777 /tmp would resolve your issue.)
Try using dtrace to see if mysqld is actually opening a socket, and if so, where. You'll also be able to tell what config files are being read by the server, although that doesn't seem to be the issue since passing --socket=... doesn't work.
I'm used to strace on Linux but recently started using dtrace at work. Here's a pretty simple example of how to trace open(2) calls, which you could modify to trace socket creation, or just all syscalls: https://github.com/tsibley/dtrace-scripts/blob/master/trace-open.d

Mountain Lion: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

I installed mysql via homebrew. I ran the two commands brew suggests:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
When I tried to run the mysql_secure_installation script, I receive this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
A separate thread led me to believe it had to do with permissions: connect to local MySQL server through socket
I ran the suggested commands substituting their mysql directory with
/usr/local/var/mysql
Yet, the problem persists. Help!
Your socket is probably being created in a non-standard location. My Homebrew installation creates it in /tmp/mysql.sock for instance.
If you can connect to the server over the TCP/IP socket, run this:
SHOW VARIABLES LIKE '%sock%';
Otherwise, try to look for it somewhere on your system:
find / -name mysql.sock
What is the default socket defined in /etc/php.ini?
Try running
cat /etc/php.ini | grep "mysql.default_socket"