Connecting mysql on 3306 and 3007 - mysql

I am able to connect to the db instance using 3306 and 3307
mysql -hlocalhost -P 3306 -u root -proot test
mysql -hlocalhost -P 3307 -u root -proot test
This is also working.
But it is actually running only on 3307, tomcat is able to connect to db only on 3307.
What does this mean? Is it an expected output?

Normally mysql listens only to one port (default is 3306, some installations put 3007 into the startup script for whatever reasons).
If you do not have more than one instance running this should not happen.

Related

ssh reverse mysql tunnel with a aliased host

I am trying to ssh into my server and then access the mysql on localhost for quick prototype development when testing on live.
Here is my connection in the server:
mysql -h db_master_www -u game -D db_www -p
I then setup my tunnel (sp is my ssh config name)
~ssh -N -L 3336:db_master_www:3306 sp
And on my local machine
hutber#hutber:~$ mysql -h db_master_www -u game -D db_www -p
ERROR 2005 (HY000): Unknown MySQL server host 'db_master_www' (-2)
So logically I'll need to use my host as the ip and not the alias?
When you use an ssh tunnel to map the local port 3336 to the remote port 3306, you would connect to 3336 locally:
mysql -h 127.0.0.1 -P 3336 -u game -D db_www -p
Make sure to use 127.0.0.1, not "localhost" because to the MySQL client, these are not the same.

Connect to different port using MySql Command Line Client

By default I am being connected to port 3309.I need to connect to port 3307.How do I do that?
Use -P parameter, like this:
mysql -h 127.0.0.1 -P 3307 -u user_name -p database_name
Important: if you connecting to localhost - use -h 127.0.0.1, NOT localhost, because MySQL will connect by file socket, not by TCP
From command line, assuming you are on the same host, have you tried :
mysql --user root --password (mypassword) --host=localhost --port=33061
In server name specify custom port when not using default one (you can imply it only when is the standard mysql port 3306)
$servername = "localhost:33061";
you can use -P (uppercase) or --port=portnumber
sample
mysql -u root -P 13306 -p databasename
or
mysql -u root --port=13306 -p databasename
Enter this command changing your details.
after that MySQL requests the password for the connection, then enter the password.
mysql --user=user1 --host=127.16.38.1 --port=25060 -p
especially consider about -p and double Hyphen --
I am giving simple way, one liner which summarizes.
mysql -u root -p --port=3316 // I have MySQL port 3316, instead of default 3306
If the --port=3316 is not provided, then MySQL Cli protocol will try with the default port, without asking.
For any other user
mysql -u anotheruser -p --port=3316

Localhost connect MySQL Docker confusion

I created a test_mysql using the following command:
docker run -d -p 3306:3306 --name=test_mysql --env="MYSQL_ROOT_PASSWORD=123" mysql
I got the IP address using docker inspect test_mysql. The IP is 172.17.0.2.
The strange thing is that when I tried to connect to mysql server on my local using
mysql -uroot -p123 -h 172.17.0.2 -P 3306
An error raised:
ERROR 2003 (HY000): Can't connect to MySQL server on '172.17.0.2' (51)
However, if I use the localhost IP address instead it did work:
mysql -uroot -p123 -h 127.0.0.1 -P 3306
My question is why I can't connect to the container use docker inspect result while localhost IP works?
1) while localhost IP works?
Let's see again your command to start container:
docker run -d -p 3306:3306 --name=test_mysql --env="MYSQL_ROOT_PASSWORD=123" mysql
The -p 3306:3306 will "bind" the port 3306 of host to the port 3306 of the container. As a result, we can see that if there is any connections come to port 3306, they will be forwarded to the port of the container.
So, your connections on local IP will work:
mysql -uroot -p123 -h 127.0.0.1 -P 3306
See more detail on Docker page
2) why I can't connect to the container use docker inspect result
It seems your container is connected to the default bridge network(docker0 may have IP:172.17.0.1 in your case ) which is often created by default when you install Docker.
You can find more detail in Docker network page.Therefore, inside your container, you may "see" the bridge (you can try to use ping command", but from your local host, it may not know how to find/resolve the 172.17.0.2 and you got that error.

Could not log into mysql server

When I login without specifying host name, I could not login
mysql -u root -p
It displays the message
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/lib/mysql/mysql.sock' (2)
But if I use hostname, I am able to login
mysql -h 127.0.0.1 -P 3306 -u root -p
It didn't allow, even if I use localhost as my hostname
What is the reason for this?
I would check that mysql is started
service mysqld start

mysql connect hang(remote connect)

Hi when I try to connect remote mysql
mysql -u root -p xxxx -h xxxx -P 80
mysql: [Warning] Using a password on the command line interface can be insecure.
then I hang at here
Does anyone knows how to slove this
In your command you are specifyng port 80. By default MySQL works on port 3306.