No memsql.sock file in /var/lib/memsql - mysql

The error mentioned here: http://docs.memsql.com/latest/tshoot/2002/ I was getting using Ubuntu 14.04.2. The MySQL client and the latest MemSQL advised to point the 'my.cnf' config to the 'memsql.sock' file located in '/var/lib/memsql', however there is no such file.
After much searching and troubleshooting, there are similar errors but without the proper file they're irrelevant in as much that without the 'memsql.sock' file there can be no connection. I'm considering using MemSQL in production soon.

There are multiple reasons why you might observe this behavior.
First of all, note that the documentation suggests that the file is under /var/lib/memsql/data, while based on your question you might be looking for it under /var/lib/memsql.
It could also be that your MemSQL is not installed in /var/lib/memsql, but in some other place. In this case the memsql.sock file will be in the data subdirectory of the directory where your MemSQL is installed.
Finally, it could be that your memsql.cnf is missing the socket argument. You need to configure both the client and the server to use the same socket. The documentation page you pointed to suggests to change /etc/mysql/my.cnf -- that's the client config. Your server config is in the memsql.cnf file, which is most likely in /var/lib/memsql/memsql.cnf. Make sure it has the following line:
socket = memsql.sock
Then as you restart MemSQL, it will create the memsql.sock file.
If none of this works, you can also just connect to 127.0.0.1 instead of localhost, in which case the memsql.sock file will not be used.

If you use the mysql client without -h 127.0.0.1 it will try to connect to the socket, which by default is set to /var/run/mysqld/mysqld.sock. This is typically set in /etc/mysqld/my.cnf or wherever your my.conf file is. If you change your $HOME/.my.cnf file to have
[client]
port = 3306
socket = /var/lib/memsql/data/memsql.sock
this should work. Note, this is a behavior of the mysql client not MemSQL.

Related

Trying to connect Django to MySQL. Connection error when migrating (Xampp, Linux)

I've been working for several weeks on Django. So far I have made 2 small projects. Now I tried to connect Django to the MySQL database.
First, I started a new project.
Then made a new app and updated the app in settings.py.
After that I changed the database in the same file settings.py with my settings.
Made a small model (in the file models.py).
Installed all the necessary apps, (pip install) mysqlclient etc,
Made the first migration successfully with
python manage.py makemigrations
So far so good!
Next, I tried to make the second migration (python manage.py migrate), as in the instructions.
Then the error message appears:
'error 111, can't connect to database'
Made some changes in the settings file, including SQL mode strict_trans_tables.
Now it shows me the error:
Can't connect to local MySQL server through socket ... Missing file .../mysql.sock.
I looked up the directory and there was no such file.
In the file my.cnf the filename and path is different!!! And exists! (It is using this existing file in my.cnf, but after executing the commang migrate it is searching for this file in a place, where it does not exist!)
To clarify things a little bit, the exact message of the error:
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
There is no such file in the current directory (as I have checked).
my.cnf file contains the following path and filename:
socket=/opt/lampp/var/mysql/mysql.sock
There is a file in the current directory. MySQL works, as well.
What is going on and what to do?
=================================
Since my issue has been resolved, I how start thinking about what could cause such issue in the first place!
Apparently Django didn't know the path to the my.cnf file, even if it exists, so it had to be implemented manually from the settings.py file with the short code I have written below.
Recently I have been working on a similar projects, involving usage of javascript and node.js as a mean to create a website with access to database from mysql of the Xampp. I am using Linux for both projects, thus it might be related to the specifications of the system. Again in the node.js project I had to implement manually the path to the socked file, as follows:
const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
// THE PATH TO THE SOCKET FILE:
socketPath: process.env.DB_SOCKET_PATH
});
And thus I stated wondering why this issue has happened in the first place?? As I said, I could only suppose it might be related to the Linux version I am using (Linux Mint 20.3), or the way it was installed. When you start working with computers it is much easier to know what caused the problem, rather than only the correct solution.
Thank you very much in advance!
You have reached an issue which suggests a MySQL problem. It is wise to try and connect to MySQL directly at this point, because if that's successful, then you know for sure that your issues are on the application settings' side and if it's unsuccessful, then you need to solve MySQL's connectivity first and only then switch to your app's settings.
Now, the error clearly suggests that MySQL's socket file cannot be found.
First, let's check whether MySQL is running at all. In Ubuntu Linux the command to do so is
sudo service mysql status
If you use something else as an OS, then of course you will need to operate slightly differently.
In Ubuntu, if the command above yields something like
Unit mysql.service could not be found.
, then the service does not exist and you need to install it.
Otherwise, if the service exists but is not running, then you will need to start it if you are able. If not, then you have some maintenance to do.
Finally, if the MySQL service is successfully running, try connecting to it via cli, like:
mysql -u <youruser> -p
The -p at the end signifies that a password will be used, so after running the command above you will need to type in the password (if everything goes well).
If you get the same socket file-related error (which presumably will happen), then you will need to find the location of the socket file (.sock) and update MySQL's cnf file (/etc/my.cnf in Linux) so that it will take into account the correct location of the socket file:
socket=/var/lib/mysql/mysql.sock
Finally the Django project was able to start using the MySQL database!!!
The changes in the file setting.py are the same as before, as follows:
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_db',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
the only thing that had to be done in addition to this, was to include the path of file my.cnf manually:
'OPTIONS': {
'read_default_file': '/opt/lampp/etc/my.cnf',
},
Obviously, this was the reason in the first place the path to the socket file to be mistaken.
But why in the first place this error occurs, I don't know. Perhaps somewhere after the installation some other path was given, but I don't know where is this path, pointing to other directory of the socket file separately, or to other path for the my.cnf file.
With the PostgreSQL database the connection was made so simply, it required only the 1st changes in the settings.py file.
After that, additional migrations were made without any disturbance, as well as the superuser account.
The source website from which I was able to use as a cheat sheet for the complete process:
https://www.digitalocean.com/community/tutorials/how-to-create-a-django-app-and-connect-it-to-a-database

idea [08S01] Communications link failure

I just use IDEA recently and want to use IDEA to connect MySQL(8.0.12).but the IDEA indicate below
However, I use cmd could connect to my database,thus I did not configure out the problem.
I am in serah of many ways to solve this problem on tech forum but those are not working.
change mysql to lower version driver
set time_zone
add properties on url
There are a couple of things to check to solve the 'Communications links' failure.
One thing in particular is to check whether your MySQL server accepts TCP connections. In your terminal, it looks like you are using named pipes.
Make sure your MySQL server allows TCP connections; check for the bind-address configuration in mysql.ini under [mysqld] section. Its value should be at least 127.0.0.1, or set it as * to bind to all (not always a good idea).
Another point is the skip_networking configuration. Check if you have that, and remove and restart MySQL server. I believe this is set by default when you are installing MySQL.
(Also note that 8.0.17 is 'ancient' already).

unable to connect to mysql socket from C program

I am developing a C program that accesses mysql. I have the following line in my code:
sts = connect_to_server(&mysql, "localhost", "my_username",
"my_password, "my_databasename");
with the actual values replaced, of course. I get:
Failed to connect to MySQL: Error: Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
I have seen other questions like this, and the answer is usually that the server is down. In this case it is not. PHPMyAdmin can access the server just fine.
And many of the other responses said to check for the socket file. It is present
(/Applications/AMPPS/mysql/tmp/mysql.sock).
Could this be something to do with paths or something? It isn't adding the path to "/temp/mysql.sock" and therefore can't find it?
I know very little about unix. I have been running OSX for nearly 10 years, but I almost never go down to that level.
Take a look into the mysql configuration file (typical my.cnt somehwhere under /etc) and adjust the value for socket to fit your needs.
Alternativly you could just link /tmp/mysql.sock to /Applications/AMPPS/mysql/tmp/mysql.sock:
ln -s /Applications/AMPPS/mysql/tmp/mysql.sock /tmp/mysql.sock
I think wrong my.ini is getting loaded. By default it looks at /etc/my.ini so if it is present just rename or delete it. Restart your MySQL Server.

MySQL does not work on localhost without Local Area Connection

I use WampServer (Apache, PHP, MySQL) and have no problems when some kind of network adapter(wireless or lan) is connected (i.e. Local Area Connection has status connected) even if i am not connected to the internet (for example when i am connected to the router but that is not connected to the internet).
When there is no network connection, I get a php error like MySQL could not connect to 127.0.0.1 on port 3306.
Interestingly, telnet 127.0.0.1 3306 says that it could not connect to the port, even when the server and MySQL are running fine (i.e. when some kind of local area connection is connected).
So I turned off all kinds of firewall (antivirus and Windows) but still no difference in anything. And that is why this issue is quite puzzling.
Things I have already tried (will update this list along the way):
The skip-networking directive in my.ini.
You could modify your MySQL server and client configuration to connect to one another using a named pipe instead of a TCP/IP loopback connection. That way, the current state of the network connection should have less impact.
To do so, start the server with --enable-named-pipe or the corresponding config file setting, and execute the client with --pipe or --protocol=PIPE. Similar configurations should be available for your PHP connector as well. It may depend on which library you use there, and whether or not it will take the mentioned configuration settings from the my.ini file (settings without leading -- there).

Connecting to SQL process with Zend

I'm trying to connect my Zend application to a MySQL process running on a shared server. The basic config should be fine, as it was working with a LAMP server.
The problem is, I need to specify the host as being the an sql process: myprocess.db, rather than localhost:
resources.db.adapter = PDO_MYSQL
resources.db.params.charset = "utf8"
resources.db.params.host = mysqlprocess.db
resources.db.params.username = username
resources.db.params.password = password
resources.db.params.dbname = dbname
However, when I do, I get this:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]:
Can't connect to local MySQL server through socket 'please_see_the_faq' (2)
in /f5/metamusic/protected/application/controllers/SearchController.php on line 418
The host I'm using is NearlyFreeSpeech, and this message is apparently triggered when attempting to connect to SQL without specifying the process you're interested in:
http://faq.nearlyfreespeech.net/section/mysql/mysqllocalhost#mysqllocalhost
Using the same details and mysql_connect($server, $user) works without issue, so it looks like Zend is somehow not using the correct host parameter.
Any ideas what's going wrong? Any help would be much appreciated.
try using
resources.db.params.host = myprocess.db
The host in the db config has to point to a database server. localhost or 127.0.0.1 are references for the database being on the same server as the application. In a hosting environment you usually have the server on a remote server so the host has to be either an IP address or a DNS name for the host.
Check the second question in the FAQ.
Update
My bad, that is about DSN and not DNS. Still, that's where the problem is. The resources.db.params.host directive in the config expects a reference to the database server and myprocess.db is neither a DNS name nor a IP address. You probably need localhost for that but then you will still be missing the DSN. I currently don't see how you set a DSN in PHP for MySQL and therefore Zend. Have a further look at this MYSQL DSN.
Update 2
You are correct with the socket and that this is related. I think the problem is the Zend PDO_MYSQL adapter. Zend funnels this directly to PDO(). There are this additional config options I mentioned above (MYSQL DSN) which is missing in the Zend implementation. Although the PDO_MYSQL adapter overrides the connect() method it does not look for this options.
However, there is another adapter mysqli which connects directly to MySQL and actually the same way as your test with mysql_connect(). It uses mysqli_real_connect() instead and that connection might understand the process name for the socket. So, you can try the following in your config:
resources.db.adapter = "mysqli"
I'm posting my eventual solution here for future reference:
It turns out, the database connection was already working. However, my call to mysql_real_escape_string() was failing, and the resulting error message suggested that the entire database connection had failed.
The solution was simply to replace the above call with Zend_DB_Adapter's quote(), and suddenly everything works.
Why this works on a LAMP machine and not a shared server, I have no idea. For now though, this is a good enough solution!