Changing the default mysql socket path - mysql

I'm setting up a new Ubuntu computer, namely mysql. I've various rails app that use mysql on the socket /tmp/mysql.sock, and as they're group projects I can't change their db config options.
"mysqladmin -u root -p variables | grep socket" tells me my socket is /var/run/mysqld/mysqld.sock. I also have a mysql directory /etc/mysql.
I've read that I'm supposed to add the socket path to the my.cnf file in the etc/mysql directory, however it is locked for editing, and somehow reverts ownership immediately if I use chown to try and change it.
Please advise me how I can change where mysql sets its default socket path.

I am also trying to get to the bottom of this, but have yet to find the definitive answer. It looks like the socket path of mysql is different between a mac and a ubuntu machine.
I initially created my app on my mac, where the socket path is:
/tmp/mysql.sock. When I tried to run rake db:create on my ubuntu machine it kept complaining that the socket does not exist. I had a look at what it is called on my ubuntu machine, which was /var/run/mysqld/mysqld.sock. When I switch it out in database.yml it seems to work, but I guess I will have to keep both options in my file and uncomment based on which environment I am working in.
Hope that helps!

Related

Manjaro Linux: I can't run Mariadb because missing socket

Well, I have Manjaro/Linux 17.0, and I've tried to install MariaDB but I always get the same error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")
I don't know what to do, I've search in thousands of forums, I can't start the mariadb's deamon with systemctl, I tried to do a touch at /run/mysqld/mysqld.sock but then it refused my connection when I tried to start mariadb, and I tried to uninstall/reinstall MariaDB, but it's the same thing :(
In all my directories I can't find mysql.sock or similar.
Help me please!
I had the same problem, the solution which worked for me is https://serverfault.com/a/813123 , I just cleaned:
sudo rm /var/lib/mysql/*
then initialised the database:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
It seems like there might be a difference between what the server is using as the socket and what the client thinks should be the socket.
You can check the process list (ps -ef | grep mysql) and see if the server is running with a different socket setting than you expect. (Look for --socket=.)
Edit your /etc/my.cnf, find or make a [client-server] section, and set socket to a file that makes sense. It should be in a directory that users have access to. The default setting is socket=/tmp/mysql.sock, so that should be a safe bet. Then remove any other socket setting elsewhere in /etc/my.cnf or files in the /etc/my.cnf.d/ directory. Then restart, and it should hopefully work.
Also check if you have a personal config file ~/.my.cnf, look for a socket setting in there, and if so remove it.
For reference, see the socket entry in the MariaDB KB. Also, have a look at the full list of locations where MariaDB config files could be stored here.

Can't connect to local MySQL server through socket (From time to time)

I have a LAMP stack setup. Occasionally, I get the following error message when I open some page from the browser:
Error creating the connection!: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I think the server was configured correctly. The problem happens about every two months. Every time when I reboot the Linux server, or restart mysql, the problem was gone. I want to fix this problem permanently. Can anyone give me some idea?
Much appreciated.
EDIT
The problem occurs again and I checked the mysqld.sock file, it was not there. Do you have any idea how to fix the problem? – Ryan Jul 23 at 16:24
If your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with
socket=/var/run/mysqld/mysqld.sock
modified
#bind-address = 127.0.0.1
to
bind-address = localhost
you can check if mysql is running with the following command:
mysqladmin -u root -p status
try changing your permission to mysql folder. If you are working locally, you can try:
sudo chmod -R 755 /var/run/mysqld/
And then restart the mysql.
Good luck.
Could it be the log file getting too large and rebooting flushes it. See this in docs on server maintenance and logfiles. Also see discussion at digital ocean. Appears to be confirmed by discussion at serverfault
You could try change the permission of your MySQL sock file like this:
chmod 777 '/var/run/mysqld/mysqld.sock'
It is a test to see if whatever user mysqld is using, it will acess your mysqld.sock file. So, reboot your MySQL and change the permission of mysqld.sock. And you need to check that if your sock folder can be accessed through any mysqld process.
If the mysqld.sock file doesn't exist, that is to say your config file is not correct.Check your mysql config file in /etc/mysql/my.conf, find the socket config just as Vanya Avchyan says.
I think the socket config is /var/run/mysqld/mysqld.sock, but in fact your mysql process runs in other place sock file.
I used to met that problem, the real socket file exists in /tmp/mysqld.sock.
So run
sudo find / -name 'mysqld.sock'
to find the real sock file and change my.conf to this real place, restart your mysql. May have work.

MySQL is not found anywhere on computer

I have recently installed MySQL directly from the website (mysql-5.7.9-osx10.10-x86_64.dmg) and I have run into a great deal of difficulty that started with trying to change the given password. The error that was returned was:
[Warning] Using a password on the command line interface can be
insecure. mysqladmin: connect to server at 'localhost' failed error:
Can't connect to local MySQL server through socket '/tmp/mysql.sock
(2)' Check that mysqld is running and that the socket:
'/tmp/mysql.sock' exists!
From here I attempted to find the "usr" folder (hidden files are showing) or even anything that closely resembles MySQL anywhere on my computer and got nothing except for installation .dmg files.
I know that MySQL was installed because it is now able to be started and stopped in the System Preferences pane, but clearly none of my commands are working and I keep getting this error no matter what I do:
mysql: command not found
Can someone give me some clue as to what I am missing? I've become fairly desperate and can't figure out what I am doing wrong. I am running El Capitan.
Well, if you're saying that MySQL is running, you can try looking for it via terminal command like this:
ps aux | grep mysql
which should give something like
12345 ... 5 Apr16 9:09.32 /usr/local/Cellar/mysql/5.6.17/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.6.17 --datadir=/usr/local/var/mysql --bind-address=127.0.0.1
so basedir and datadir is probably the most valuable outputs here (please note that your path most likely will be different).
On top of it, in order to get mysql command running through terminal you have two options
Create simulink from mysql's basedir into your /usr/local/bin directory
ln -s /usr/local/Cellar/mysql/5.6.17/bin/mysql /usr/local/bin/mysql
Add mysql's basedir/bin to your path (need to add this to your ~/.bashrc to make it persistent)
export PATH=/usr/local/Cellar/mysql/5.6.17/bin/:$PATH
New terminal tab is required for these changes to catch up.
Cheers.

app can't connect to local MySQL - osx

I am running some rails app on osx, but when I launch a rails generate command type, I get this message :
/$root/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect': Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql2::Error)
For info, my mamp server is running, and the connection must pass through /Applications/MAMP/Library/bin/mysql, so I aliased it by setting in my bash profile :
alias mysql="/Applications/MAMP/Library/bin/mysql"
Btw, what is weird, is that my rails s command works perfectly, so my app can connect to the apache server in that case
So the trick was to simply /tmp/mysql.sock to /Applications/MAMP/tmp/mysql/mysql.sock
ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
The error indicates that "mysql is not started/running". From what you describe, looks like the new location pointed to the alias has no mysql or its mysql is not started.
Look my.cnf file with the correct parameters in the new location:
/Applications/MAMP/Library/bin/mysql
Another trick is to list your running processes and look for mysql.
Also, are you sure, "rails c" is not using the sqlite3 vs mysql?
Updated:
*Courtesy of #bfavaretto
MySQL my.cnf location on OS X?
By default, the OS X installation does not use a my.cnf, and MySQL just uses the default values. To set up your own my.cnf, you could just create a file straight in /etc.
OS X provides example configuration files at /usr/local/mysql/support-files/
Update:
Take a look at this:
https://stackoverflow.com/questions/4788381/getting-cant-connect-through-socket-tmp-mysql-when-installing-mysql-on-m

Error 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I'm on Ubuntu 11.04. Everything works PHP, PHPMYADMIN, manual login to MySQL etc.
I have written a C application that uses MySQL. Now, when I start this application I receive the above error. I tried to prevent that from happening by linking the original file into the /tmp/ folder (ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock), however, after a while I start getting this error again - because my link has been removed, which is frustating.
What do I need to do to make this work?
The MySQL libraries are compiled with a default of /tmp/mysql.sock. The server is started up with /var/run/mysqld/mysql.sock and your $HOME/.my.cnf does not reflect this value in the [client] section.
If this is run without a valid $HOME you may need to use mysql_options with MYSQL_READ_DEFAULT_FILE.
Try linking the file in other location than /tmp/ and use it from there