MySQL connection via terminal failing - mysql

Hi I am using Linux/Ubuntu and I am having a problem on logging in on mysql
when I run the code:
sudo mysql -h localhost -u root -p
I got an error that says:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/obitnami/mysql/tmp/mysql.sock' (2)
How can I fix this?
I am using:
mysql Ver 14.14 Distrib 5.5.22, for debian-linux-gnu (x86_64) using readline 6.2
rails 3.2.3
ruby 1.9.3
Please help

First you can try to see if it is running at all with command
ps aux | grep mysql
Mysqld should be there.
Check also if listening address, because it might be your outside address instead of localhost with command:
netstat -antp |grep mysql
Then check your config file to see where exactly your socket file is being written. After that you have verified that it's up and running you can try to connect to it with command
mysql -u root -p -S /path/to/socket.file
It's possible that you have socket file on other place and because of it you can't connect to server. -h localhost is not needed if you are connecting to localhost because it's assumed if -h is not used that you are connecting locally but it might be needed if your listening IP address is external one and not internal (127.0.0.1 for localhost or 0.0.0.0 for all addresses).

Related

Error mysql: unknown variable 'ssl-mode=VERIFY_IDENTITY' connecting to Mysql RDS using certificate

While trying to learn about aws services, I'm trying to connect to RDS instance from my ec2 instance using certificate.
I'm using this command to connect -
mysql -h <aws-account>.rdsinstance.<region>.rds.amazonaws.com --ssl-ca=rds-ca-2019-root.pem --ssl-mode=VERIFY_IDENTITY
But i get this error -
mysql: unknown variable 'ssl-mode=VERIFY_IDENTITY'
I'm able to connect without certificate using this command:
mysql -h .rdsinstance..rds.amazonaws.com -P 3306 -u admin -p
Has anyone seen this before? I searched around but couldn't find anything that would help me.
If you have any suggestions/solutions please let me know
MyMysql version:
mysql --version
mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1
Looks like mysql --help does not have --ssl-mode option. I removed it and was able to connect. (below is the command i used, just for reference)
mysql -h <aws-account>.rdsinstance.<region>.rds.amazonaws.com --ssl-ca=rds-ca-2019-root.pem -u <user> -P 33306 -p
in mysql firing >'status' command confirmed SSL is being used for connection.

Connecting to a mysql running on a Docker container ubuntu 16.04

I have mysql container on docker. Mysql is running correcty now(because my application is running).
When I type docker-compose ps I see mysql is up. This is related part in pom.xml :
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://127.0.0.1:3310/fraud_dev</url>
<defaultSchemaName>abc_dev</defaultSchemaName>
<username>abc_dev</username>
<password>abc_dev_123</password>
I am trying to connect mysql on localhost terminal. I am typing this :
mysql -u 'abc_dev'#'localhost:3310' -p
I am typing password. Then I am getting this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I dont know where I am wrong. How can I fix it?
Thanks.
You do not use the standard mysql port 3306. Because of this you have to specify the used port with
mysql -u abc_dev -p -h localhost --port 3310

How can i connect to mysql using terminal?

I'm trying to connect to the mysql server on my mac using terminal. I've already got MAMP on my mac but now I have installed XAMPP. when I type this into my terminal
mysql -u root -p
it comes up with this message...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/Applications/MAMP/tmp/mysql/mysql.sock' (2)
I'm wondering is it because of XAMPP? Any suggestions?
have you tried
mysql -h 127.0.0.1 -u root -p
(if the mysql server isn't running on your local box, substitute the IP address of the mysql server for 127.0.0.1)

Can not connect to MySQL Server by 127.0.0.1

I'm using Ubuntu 12.04 32bit AND MySQL Server 5.5.31
I can connect to MySQL Server with following command successfully :
$ mysql -u root -p -h localhost
But when i'm using 127.0.0.1 instead localhost can not connect :
$ mysql -u root -p -h 127.0.0.1
The error is :
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
Any ideas would be awesome.
Maybe the allowed host for root is 'localhost' and your host doesnt map 127.0.0.1<->localhost correctly?
Try setting the host for this user to 127.0.0.1 or % (allow ALL ips to connect)
Have you uncommented the my.cnf's line
skip-networking
Please check this http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html for a solution.
Update my.cnf file to include the following line
bind-address=128.2.177.192

Connecting to MySQL through Cygwin

I have XAMPP running on my desktop and can connect to the MySQL server via phpMyAdmin. However, when I try to connect through Cygwin:
Error: Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)
I've tried connecting to MySQL on the same machine, my local dev server and my remote server, all failed.
mysql -h 127.0.0.1 -P <PORT> -u root -p
This is what worked for me. Make sure you check what is the correct port.
Check the mysqld PID with:
ps -sW | grep mysqld
And then find the PORT with:
netstat -nao | grep <PID>
Have fun!
you can also add the alias of itself.
alias mysql = 'mysql -u {user} -p{password} -h 127.0.0.1'