Question
My assumption is MySQL Workbench runs this:
mysql -h localhost -P 3306 -u user -p
How can I make it run this?:
mysqle -h localhost -P 3306 -u user -p
Reason
I am working with a client who runs two instances of MySQL on one server. The command mysql does not launch MySQL as it normally does. Rather, they use mysqle and mysqlw. I believe this is the cause of a MySQL Workbench error when attempting to connect with Standard TCP/IP over SSH:
Lost connection to MySQL server at 'reading initial communication
packet', system error: 0
This error has been documented, but I believe is unrelated.
Related
I want to change the default exposed port for mysql docker container, but if i try to use this command:
docker run --detach --name=test-mysql -p 52000:52000 --env="MYSQL_ROOT_PASSWORD=mypassword" mysql
It does not work. mysql -uroot -pmypassword -h 127.0.0.1 -P 52000
Warning: Using a password on the command line interface can be insecure.
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
If I use the standard port 3306:3306 then it works fine, but i want change the port. Is it possibile?
I had already tried -p 52000:3600 , but i have always gotten:
mysql -uroot -pmypassword -h 127.0.0.1 -P 52000
Warning: Using a password on the command line interface can be insecure.
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
You need to map the container-port 3306 on the prefered TCP port (of your server):
-p <host_port>:<container_port> (map container_port xx on host_port yy)
So for your mysql
docker run --detach --name=test-mysql -p 52000:3306 --env="MYSQL_ROOT_PASSWORD=mypassword" mysql
there is also a second option:
don't map a port to another port but let mysql itself run directly on another port using the MYSQL_TCP_PORT-variable.
example:
docker run --detach --name=test-mysql --env="MYSQL_TCP_PORT=52000" mysql
I created my container like this:
$ docker run -d -p 33060:3306 myimage
Then I try connect from host to mysql server in container:
$ mysql -uroot -proot -P 33060
I got this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
It odd because in Navicat only I changed the port and work fine:
But If I have the IP of the container:
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' mycontainer
172.17.0.55
Then I can connect to mysql server successfully:
$ mysql -uroot -proot -h 172.17.0.55
But it is a tedious task have to check the ip each time I create a new container to connect to mysql. There any settings I can do to make this task simpler?
This is not a Docker issue. By default the mysql command-line client will connect to a local (Unix) socket instead of a network one, even if you specify -P.
This behavior is described in the documentation:
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given
You have to pass the -hlocalhost option, or you can set your connection defaults in /etc/mysql/my.cnf
This question is in relation to
Dockerized web app connecting to MySQL DB on host
I am trying to open up a connection from a docker container to the host to support MySQL connections.
The way I understand it I should be able to execute the following in my container
nc.traditional -l -p 3306 -c "nc.traditional 172.17.42.1 3306" &
to open up a tunnel from the Docker container port 3306 to the host (IP 172.17.42.1) MySQL instance, running on port 3306.
Trouble is as soon as I try to connect from the container
mysql --host=127.0.0.1 --port=3306 -uroot -ppassword
I get an error and the tunnel exits
root#7ec710b77baf:/var/log# mysql --host=127.0.0.1 --port=3306 -uroot -pAcc355
(UNKNOWN) [172.17.42.1] 3306 (mysql) : Connection refused
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
[1]+ Exit 1 nc.traditional -l -p 3306 -c "nc.traditional 172.17.42.1 3306"
Why would the tunnel exit? What am I doing wrong? It certainly seems to contact the MySQL instance as I get a different error message when I try a different port.
I haven't been able to find any info in logs or on std out to help.
Any ideas?
From my experience you're probably after socat rather than netcat.
eg
socat TCP-LISTEN:3306,fork TCP:db-host:3306
I've found issues with netcat handling the connection
I want to connect to remote MySQL via ssh tunnel with user that has 'localhost' access.
I use this to make a tunnel:
ssh -f -N -L 33306:localhost:3306 user#remote-host
and this to connect to host:
mysql -h 127.0.0.1 -P 33306 -uuser -ppassword
The error i get is:
ERROR 1045 (28000): Access denied for user 'user'#'remote-host' (using password: YES)
The problem is that user 'user'#'remote-host' (or 'user'#'%') does not exist, only 'user'#'localhost' does.
Is there a way to force remote host, without server-side modifications into thinking that i come from localhost? That's the only reason I would do the connection via ssh tunnel anyway.
Note:
If I want to connect with this command:
mysql -h localhost -P 33306 -uuser -ppassword
I get this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Additional data:
On remote server in /etc/hosts the values are like this:
127.0.0.1 localhost
remote-ip remote-host
The simple way to create MySQL Tunnel to REMOTE HOST:
$ ssh -fNL TEMP_PORT:localhost:MYSQL_SERVER_PORT USER#SERVER_NAME
Test:
$ mysql -u root -p -h 127.0.0.1 -P TEMP_PORT
Please note that localhost and 127.0.0.1 are treated differently in mysql on unix.
Quoting:
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file
http://dev.mysql.com/doc/refman/5.7/en/connecting.html:
Furthermore, mysql client would silently try to use a socket file even if you explicitly specify -P on your command line:
This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1
Effectively, using this command
mysql -h localhost -P 33306 -uuser -ppassword
you're simply trying to connect to your local mysqld which is missing
Considering this, your question boils down to connecting to a remote server available over a domain socket.
If installing additional software meets your requirements 'without server-side modifications' you could use socat as described here:
https://www.debian-administration.org/users/dkg/weblog/68.
Tailored for mysql, it could work as follows:
install socat on both ends
socat "UNIX-LISTEN:your_local_path/mysql.sock,reuseaddr,fork" EXEC:'ssh user#remote-host socat STDIO UNIX-CONNECT\:/your_server_path/mysql.sock"
mysql -S your_local_path/mysql.sock -u user
I've got mysql 5.1 on a windows xp machine. It's listening on port 3308. I'm trying to use mysqldump:
> mysqldump -u root -pmypassword dbname > out.sql
Getting an error:
mysqldump: Got error: 2003: Can't connect to MySQL server on 'localhost' (10061) when trying to connect
Not sure what the problem is, looking at --help dumps variables and shows port=3308 as I set in the mysql installation (instead of default 3306). I don't think there's anything different with my installation. I also tried explicitly setting the port # on the command line but still same error.
Thanks
To connect through a port (and not the default 3306), use:
mysqldump -u root -pmypassword -P 3308 dbname > out.sql
Besides that, a simple test to see if MySQL responds at port 3308 is to try telneting:
telnet 127.0.0.1 3308
If MySQL is listening on port 3308, it'll respond with an error and the version running.
Go to run type services.msc
then
locate mysql service and start it .this solved
If your Mysql-Client is 5.5.16 please upgrade it to 5.6.10, this process worked for me if your mysql server is 5.6.10.