MySQL hell... can't connect to database /tmp/mysql.sock - mysql

Update: I've STOPPED the older mysql process which was running and causing some confusion. Now I think I have only the newer (5.1.40) version running. BUT, it's pointing to the wrong data file. It's pointing to a default install data file and I'd like it to point to the existing data file in /var/mysql. Here's a portion of /etc/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /var/mysql/mysql.sock
this is pointing to the older mysql.sock. I can't seem to find in the directory tree of the newer MySQL install?!? unless it's somewhere obscure.
Anyone help? Basically I installed a newer MySQL and now need to get this new version to launch with my existing data. And sort out this mysql.sock thing....
I've recently updated MySQL on Mac OS X Server and am having a hell of a time connecting to it from a rails app. or consistently from the command-line for that matter.
i'm sure this is an obvious error on my part but I only have moderate command-line experience so hoping someone can help...
also related is my rails app no longer can connect. Failing to connect via /tmp/mysql.sock but I'm not sure why it's looking there because there is no mysql.sock in /tmp and I don't know what/where it should be....
Edit: adding results from mysql_config --sockets
$ mysql_config --sockets
Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
Options:
--cflags [-I/usr/local/mysql/include -g -Os -arch ppc -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL]
--include [-I/usr/local/mysql/include]
--libs [-arch ppc -L/usr/local/mysql/lib -lmysqlclient -lz -lm -lmygcc]
--libs_r [-arch ppc -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm -lmygcc]
--plugindir [/usr/local/mysql/lib/plugin]
--socket [/tmp/mysql.sock]
--port [0]
--version [5.1.40]
--libmysqld-libs [-arch ppc -L/usr/local/mysql/lib -lmysqld -ldl -lz -lm -lmygcc]
Edit2 which mysql_config
$ which mysql_config
/usr/local/mysql/bin/mysql_config

You are trying to use different sockets for the server and client. Your Rails is trying to connect to /tmp/mysql.sock, by MySQL is listening on /var/mysql/mysql.sock.
Normally MySQL configuration is stored in /etc/my.cnf, but in your ps your output I see socket path is given as a parameter. So really depends on your system's specifics.
Anyway, look in /etc/my.cnf and your database.yml and make sure mysql.sock appears at the same path in both files.

Not sure whether this will completely solve your problem (you may need to fix the socket path as suggested by cababunga), but try 127.0.0.1 to bypass the socket connection and establish a TCP one.

The function real_connect in the Ruby MySQL module actually takes a bunch of parameters:
real_connect(host,user,password,db,port,socket,flags)
The one you need to change is the "socket" parameter. On my Python apps on Mac OS X, I have to set that socket parameter to be /var/mysql/mysql.sock.
So notice, it's not the host you need to change, it's the actual socket. Is there a socket: parameter you can use in your config?
So here's what you can do...
Run the command mysql_config --socket on your command line in a terminal in OS X and it should return you the value of the "socket" you need to use (probably /var/mysql/mysql.sock).
Then in your database.yml file, make sure you add the line:
socket: /var/mysql/mysql.sock
I've mostly run into this via Python on OS X and fixed it in a similar fashion, but I'm going to guess that Ruby will give you the same issue.

Related

change socket address mariadb_config

I can't understand what follows, can someone explain me and help me solve the problem?
I have a mariadb-server a front-end application in C.
I have 2 make files and i'd like that i can use both of them.
The first one is this
all:
gcc -g src/*.c -o applicazione `mysql_config --cflags --include --libs`
clean:
-rm applicazione
and it works. If i compile with this, my application runs without any trouble.
The second one is this
all:
gcc -g src/*.c -o applicazione `mariadb_config --cflags --include --libs`
clean:
-rm applicazione
The difference is that in the first I used mysql_config, while in the second I used mariadb_config.
My problem is that with the second makefile, (after some problems) I can successfully compile, but as soon as I try to connect to the server I get this error
fabiano#fabiano-HP-15-Notebook-PC:~/Scrivania/BackupProgetto/0226198$ ./applicazione
Inserisci Matricola: g1
Inserisci Password: *
Connection error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Reading on the net i understand that the problem is that the socket is not where my application try to find it.
Indeed if i execute sudo mariadb and after that \system i can read this
UNIX socket: /var/run/mysqld/mysqld.sock
Now my questions:
why my application run successfully with the first make file but it doesn't with the second one ?
what can i do for let my application works with both make files ?
My OS is Ubuntu 18.04.3 LTS.
If you compare output from mysql_config --libs with output from mariadb_config --libs you will probably notice that different libraries from different locations will be used.
mariadb_config is part of MariaDB Connector/C, the default build uses /tmp/mysql.sock for the socket file:
IF(NOT MARIADB_UNIX_ADDR)
SET(MARIADB_UNIX_ADDR "/tmp/mysql.sock")
ENDIF()
The libraries from mysql_config output were compiled with default socket located at /var/run/mysqld while the libraries from mariadb_config where compiled with socket located in the tmp directory.
There are several options to fix that:
1) Change the socket in your my.cnf file. This needs to be done in [mysqld] section, but also in [mysql] section to make sure that the client tools will work properly.
2) Set the environment variable MYSQL_UNIX_PORT to /var/run/mysqld/mysql.sock before running your application
3) If you build MariaDB Connector/C on your own:
cd mariadb-connector-c
mkdir bld
cd bld
cmake .. -DMARIADB_UNIX_ADDR=/var/run/mysqld/mysql.sock
cmake --build .
4) Before connecting you can specify the location of the socket in your application:
mysql= nysql_init(NULL);
rc= mysql_options(mysql, MARIADB_OPT_UNIXSOCKET, "/var/run/mysqld/mysql.sock");

Why is mysql_config reporting the wrong socket file location?

The mysql_config program is reporting the socket file location as:
/var/lib/mysql/mysql.sock
But in /etc/my.cnf, the location is clearly stated as:
/tmp/mysql.sock
When I use "mysqladmin variables" to check the socket, it is reported correctly. Why is mysql_config incorrect, and how can I fix it?
mysql_config --socket shows "The default Unix socket file, defined when configuring MySQL" (i.e. at compile-time).
What OS are you using?
I use OSX and it very rarely uses default locations for, well, anything!
The '/tmp/mysql.sock' value is the default for my.cnf out of the box, as far as I am aware you should change your my.cnf to reflect your socket location in respect of your environment.
In MAMP (apache, mysql,php bundle for OSX) it is located in 'Applications/MAMPP/tmp/mysql/mysql.sock'
MAMP my.cnf [default]
# The MySQL server
[mysqld]
#port = 9999
socket = /Applications/MAMP/tmp/mysql/mysql.sock

Missing /var/lib/mysql/mysql.sock file

I'm trying to access mysql and when I run the mysql command, I get the following.
[root#ip-10-229-65-166
tpdatabase-1.8.0.28356]# mysql
ERROR 2002 (HY000): Can't connect to
local MySQL server through socket
'/var/lib/mysql/mysql.sock' (2)
Doing this returns nothing
[root#ip-10-229-65-166 mysqld]# find
-name mysql*
[root#ip-10-229-65-166 mysqld]#
/etc/init.d/mysql stop
-bash: /etc/init.d/mysql: No such file or directory
[root#ip-10-229-65-173
tpdatabase-1.8.0.28356]# mysql_config
|grep -- --socket
--socket [/var/lib/mysql/mysql.sock]
Maybe a permissions problem?
I do have mysql installed using yum install mysql
I'm running CentOS 5.4 on a Amazon EC2 Cloud Instance
You need to install the server package:
sudo yum install mysql-server
After installation, you have to start the service:
sudo service mysqld start
rm -rvf /var/lib/mysql/ib_logfile*
touch /var/lib/mysql/mysql.sock
touch /var/lib/mysql/mysql.pid
chown -R mysql:mysql /var/lib/mysql
systemctl restart mysql
try this and check the permission of both /var/lib/mysql/mysql.sock and /tmp
We faced a similar problem in my office setup with the same OS. The actual thing that was happening was low space on the server. It is quite strange, but i believe if the server gets full the files cannot be loaded or of some other resort. Please check to be sure the space on the server is enough else you have to try removing the installed mysql and reinstall. Best of luck.
just search for mysqld, this is the server daemon:
find / | grep mysqld
If you found it, the server package may be correctly installed but without initd scripts. For testing, you may start the mysql server by hand executing the above file.
mysql might have been packaged separately as client and server. Check your package repositories to make sure that the server has been installed. The mysql package might only be the client. Check if there's a package called mysql-server or something similar. Check the list of files installed by the mysql package to see if it actually installs the server.
If the files are not even there, it's not a permissions problem. Also, you're running as root.
I recently encountered this problem after an upgrade on Ubuntu 18.04. The solution here solved it https://serverfault.com/a/957723/439448.
Make sure you have privileges to access the /var/lib/mysql/mysql.sock file. And if you still get the error, create a default my.cnf file with
[client]
socket = /path/to/mysql/data/mysql.sock
[mysqld]
server-id = 2
socket = /path/to/mysql/data/mysql.sock
port = 4000 #any port you wish
basedir = /path/to/mysql
datadir = /path/to/mysql/data
and initialize the database again. Make sure you give --defaults-file=/path/to/mysql/my.cnf when you initialize. If you get error saying files exist in /path/to/mysql/data, remove them and try again. Once done, when you run mysql also, give --defaults-file=/path/to/mysql/my.cnf.
Should work.
Before hitting mysql on command prompt make sure your correct my.cnf configuration file is in placed and set the permission of etc folder as
chmod -R 777
etc folder as below list to avoid
error MySQL - ERROR 2002 (HY000):
e.g /etc/my.cnf, /etc/mysql/my.cnf, $MYSQL_HOME/my.cnf [datadir]/my.cnf ~/.my.cnf

Change port # for mysql on mac

I just installed mysql on a mac running 10.6. The mysql version is 5.1.56. I need to have mysql run on port 3307. This article says we can change the port by modifying this file:
# vi /etc/my.cnf
http://www.cyberciti.biz/faq/change-default-mysql-port-under-linuxunix/
but there is no such file in /etc. I can see mysql is running ok because I can connect to it just fine, is the way we change the port # different now?
Thanks
Looks like the new installers are adding the port as 3307
To change that follow below steps
sudo vi /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
change 3307 from this line <string>--port=3307</string> to 3306
On OSX you can create /etc/my.cnf if it does not exist. You can base it on samples found in /usr/local/mysql/support-files. Don't forget to restart MySQL for your my.cnf to take effect.
On MacOs High Sierra running MySql v8 server, you need the following:
Edit /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Under ProgramArguments, you will see many entries with
<string>...</string> etc,
Add the following line: <string>--port=16000</string>
Also, to restart you need to do the following:
launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
and then
launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
I hope this helps.
By default, the install doesn't create a my.cnf file on Snow Leopard. You can create one yourself under /etc or you can copy one from /usr/local/mysql/support-files/
Then run :
sudo cp my-huge.cnf /etc/my.cnf
Check out the explanation here
I experienced a similar problem and here's what worked for me. If you installed MySQL using brew install mysql then this should work for you.
For context, I'm using macOS Monterey 12, Homebrew 3.4.5, and MySQL 8.0.
MySQL is installed in:
/opt/homebrew/Cellar/mysql/8.0.28_1/
The configuration file my.cnf is located at /opt/homebrew/etc.
You can change the default port by specifying a new port in the my.cnf file.
First navigate to the homebrew etc folder
cd /opt/homebrew/etc
Append the new port value to the my.cnf file
echo "port = 3307" >> my.cnf
restart the MySQL service
brew services restart mysql
I tried a long time to get mysql running on my Mac (OSX 10.11.13) with mysql 5.7.11 to develop wordpress sites on my local machine...
When I used the app duplicator to migrate a website to my local machine I got errors during the database import. This was caused by to stricked sql_mode...
The trick that made it was:
Going to
/usr/local/mysql-5.7.11/support-files/
and copy the content from my-default.cnf
and paste it to
/etc/my.cnf (if this file does not exist create it!)
at the very last line of my.cnf I added:
sql_mode="NO_ENGINE_SUBSTITUTION"
Et voilà: sql_mode is changed permanently!
Whoop whoop!
I installed docker and was having problems with my company wanting to use port 3306 (which is what I was using privately).
Similar problem to you. So this is what I did to fix it.
sudo vi /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Then you get a long list of script tags and
Insert <string>--port=3307</string> into the array. Make sure you put it under the other strings and within the array.
I changed my port to 3307 instead of 3306 and now docker is working.

Run multiple MySQL server on a single machine

Can we run multiple MySQL servers on a single machine?
Thanks.
Yes, you just need to run them on separate ports and point them at different lib directories for their data.
Here's a good reference: http://dev.mysql.com/doc/refman/5.1/en/mutiple-servers.html
(If you want to use this for testing, I suggest checking out MySQL Sandbox which is now replaced by dbdeployer)
There are various methods to run multiple instances of mysql (on different ports) on the same machine. Here I have used the same binary and used a separate configuration file (with separate port, pid, socket and data directory).
We need to create new directories for our datadir and log folder (if used). Also we need to assign proper permissions on those folders:
# mkdir /var/lib/mysql2
# chown -R mysql.mysql /var/lib/mysql2/
# mkdir /var/log/mysql2
# chown -R mysql.mysql /var/log/mysql2
Next we need a separate configuration file same as a default mysql configuration file. So start by copying the existing one and changing the needed values.
# cp /etc/my.cnf /etc/my2.cnf
(or change the path appropriately for your configuration file is in a different place).
Next, we need to edit our new configuration file with different mysql port (default to 3306), the pid and socket than the default ones, and also point the data and log folders to the ones created before.
# cd /etc
# sed -i ‘s/3306/3307/g’ my2.cnf
# sed -i ‘s/mysqld.sock/mysqld2.sock/g’ my2.cnf
# sed -i ‘s/mysqld.pid/mysqld2.pid/g’ my2.cnf
# sed -i ‘s/var\/lib\/mysql/var\/lib\/mysql2/g’ my2.cnf
# sed -i ‘s/var\/log\/mysql/var\/log\/mysql2/g’ my2.cnf
Finally we need to initialize the default dbs:
# mysql_install_db –user=mysql –datadir=/var/lib/mysql2/
Finally we can start our new mysql instance with:
# mysqld_safe – -defaults-file=/etc/my2.cnf &
We can connect to our new instance using:
# mysql -S /var/run/mysqld/mysqld2.sock
or
# mysql -h 127.0.0.1 -P 3307
and if we no longer need it, stop it with:
# mysqladmin -S /var/run/mysqld/mysqld2.sock shutdown
Ref Site : https://linuxinpakistan.com/start-multiple-instances-mysql-machine
My steps on Windows 10:
Copy C:\ProgramData\MySQL\MySQL Server 8.0\my.ini to C:\ProgramData\MySQL\MySQL Server 8.0\my1.ini
Open my1.ini and modify:
port=3307(under Client and Server Section)
datadir=C:/ProgramData/MySQL/MySQL Server 8.0/Data1
report_port=3307
Copy C:\ProgramData\MySQL\MySQL Server 8.0\Data to C:\ProgramData\MySQL\MySQL Server 8.0\Data1
Run on cmd prompt: (With Administrator privileges if necessary)
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --install MySQL80-1 --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my1.ini"
If all went well, you will see:
Service successfully installed.
Win+R
Type services.msc, find the service name MySQL80-1, right-click on it and click Start.
If all went well, you will see the Status change to Running.
If it did not go well, open xxx.err file found in C:\ProgramData\MySQL\MySQL Server 8.0\Data1 to check why.
If you do not want the service anymore:
Stop it
Delete it on the cmd prompt using sc delete MySQL80-1 where MySQL80-1 is your service name.
For Windows, if the version of mysql server is different then using MYSQL Installer download and install the different versions of the MYSQL server.
Select Reconfigure for each MYSQL server and configure the PORT differently. Complete the configuration steps by clicking next until it is finished
Yes definitely,
Create multiple configuration files with different ports.
This is the best resource to understand:
Video Tutorial: MySQL Multiple Instances
Reference article: Click here