connecting error mysql db from host to docker container - mysql

I have a mysql server running on docker container.When I say docker-compose ps I see mysql is up. I have an ubuntu 16.04 host machine. I want to connect to mysql with command line.
I am trying this :
mysql --host=localhost --user=abc --password=123 abc --port=3310
but I am taking this error :
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' (2)
I dont want to go container and connect. And I should use port number 3310. Here is my related docker-compose.yml about mysql:
mysql-db:
image: mysql:5.7.11
command: mysqld --lower_case_table_names=1
ports:
- "3310:3306"
I am new on these things. How can I connect to mysql? Where I am wrong?
Thanks

Related

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61)

Since I've updated my Mac to the lastest OS version (Ventura 13.2) and I'he made some cleanup (hopefully I didn't remove any important file). I can't connect to mySql
I've insatlled mysql with brew (long before this update) and it always has worked fine.
When I run brew services start mysql in my terminal it looks to work (Successfully started mysql (label: homebrew.mxcl.mysql))
But, as soon as I run mysql -u root -p and I enter my password I have the following error message ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
When I explore /tmp directory I see that /tmp/mysql.sock is a symlink to /var/lib/mysql/mysql.sock but mysql directory doesn't exist in /var/lib.
After extensive research I didn't find how to "get" this directory.
I've found many entries in StackOverflow with the same title, I've tried almost all answer but none seems to work. especialy in my case I'm using brew and macOS ventura.
Typicaly for ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' the accepted answer is not about brew.
I've tried brew reinstall mysql.
I've tried as well mysql -h 127.0.0.1 -u root -p in this case the error is ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (61).
I've tried to run mysqld and then brew services start mysql, in this case I have the following error
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/CedMacBook1/Library/LaunchAgents/homebrew.mxcl.mysql.plist` exited with 5.
I've tried to change my password using sudo mysqladmin -u root password -p and once again I have the error error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'.
It looks like mysql is runningm, I've ran ps aux | grep mysqld and get the following line:
CedMacBook 21853 0,0 0,0 34400496 2728 s000 S+ 7:53 0:00.01 grep mysqld
Finally I've checked my /usr/local/etc/my.cnf and I have the following
# Default Homebrew MySQL server config
[mysqld]
socket=/tmp/mysql.sock
# Only allow connections from localhost
bind-address = 127.0.0.1
port=3306
mysqlx-bind-address = 127.0.0.1
At this stage I'd be happy to swipe out everything... if I could save all my database
Please help, I don't know what else to try

Cirrus CI - Can't connect to MySQL additional container

I'm running a container on Cirrus CI, and in my .cirrus.yml, I've defined an additional_container to run a MySQL instance to test against as per the docs:
.cirrus.yml
container:
image: node:latest
additional_containers:
- name: mysql
image: mysql:8
port: 3306
cpu: 1.0
memory: 512Mi
env:
MYSQL_ROOT_PASSWORD: "pa55w0rd"
I'm trying to run a CREATE DATABASE command against that instance in one of my setup tasks:
...
mysql_setup_script:
- mysql -uroot -ppa55w0rd -P3306 -hlocalhost -e "CREATE DATABASE voluble_test;"
...
I've installed the MySQL client (but not the server, as this would defeat the object) on my testing container. However, MySQL acts as if it were connecting to a true localhost DB and looks for a locally-installed MySQL server, it appears - and fails with the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
That said, the Cirrus CI docs state that the MySQL instance should be available at localhost:
Tests will be able to access MySQL instance via localhost:3306.
I can't see an obvious way around this - any advice?
Using localhost will cause mysql not to use the network.
Use either 127.0.0.1 or your docker host IP, depending on network configs.
Notice that the error is not a network error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
"through socket '/var/run/mysqld/mysqld.sock'", that file does not point to a mysql socket inside your docker container.
Grab your docker host IP with:
$ docker network inspect bridge --format='{{ (index .IPAM.Config 0).Gateway}}'

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

Rails 3.2 - Can't connect to local MySQL

When I run the app, I will get this error message:
/Users/adam/.rvm/gems/ruby-1.9.3-p385/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)
If I try to run
mysqladmin variables | grep socket
The result is:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
I am pretty sure I was working with Rails 3.2 and MySQL, but now it doesn't. I am running on Mac OS Lion, could you help me please what am I missing?
Thank you
Type ps aux | grep mysqld in the terminal and see if anything shows up besides the grep command. If not, you're mysql server isn't running. Otherwise try typing mysqld start in the terminal and see if you can't get your sql server to boot up.
Edit: Sorry, on OSX the command to start it should be mysql.server start

Starting mysql in new EC2 instance throws "can't connect through socket" error

I have an ec2 instance, but when i run mysql, it gives me this error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Similarly, when i run
/etc/init.d/mysql start
Oct 31 11:29:16 domU-12-31-38-00-A8-62 /etc/init.d/mysql[5263]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
What is wrong?
I had this same problem on an ec2 instance. These instructions worked perfectly for me:
Redhat Enterprise Linux - RHEL 5 / 6 MySQL installation
Type the following command as root user:
yum install mysql-server mysql
Redhat Enterprise Linux - RHEL 4/3 MySQL installation
Type the following command as root user:
up2date mysql-server mysql
Start MySQL Service
To start the mysql server type the following command:
chkconfig mysqld on
/etc/init.d/mysqld start
Setup the mysql root password
Type the following command to setup a password for root user:
mysqladmin -u root password NEWPASSWORD
Test the mysql connectivity
Type the following command to connect to MySQL server:
$ mysql -u root -p
Well, maybe the server is not running? :)
At the bare minimum:
ps aux|grep [m]ysql
If this returns nothing, then MySQL is not running.
Troubleshoot by adding the following to the config file: log_error=/path/to/logfile