Could not log into mysql server - mysql

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

Related

can't connect to mysql in docker from bash

I am able to access mysql via workbench with hostname: localhost and port: 3306 which were present by default, but I can't connect it via bash
mysql -u root -p
returns follwing error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
How to connect mysql in docker via bash?
You need to use the -h arugument:
mysql -h 127.0.0.1 -u root -p
The error message tells you that mysql tried to connect to the unix socket /var/run/mysqld/mysqld.sock and not to the network socket.

XAMPP and hidden service MYSQL DB cant connect

I am trying to remotely connect to my hidden service MySQL DB
mysql -u root -p -h 127.0.0.1 connected
works fine on local host
I am following this tutorial on reddit:
/r/TOR/comments/222bum/running_mysql_as_a_hidden_service/
I have xampp running on Ubuntu and and tor MySQL listens to port 3306 and Apache on 80
I am trying to connect to my DB remotely with command:
proxychains mysql -u root -p -h http://xxxxxxx.onion DBNAME
Getting this error:
ERROR 2003 (HY000): Can't connect to MySQL server on
'http://xxxxxxxxx.onion' (111)
tried this with socat
socat TCP-LISTEN:3308 SOCKS4A:127.0.0.1:xxxxj.onion:3306,socksport=9050
or
socat TCP-LISTEN:3308 SOCKS4A:localhost:xxxxj.onion:3306,socksport=9050
did not work in tor panel it says but only when i try to proxychains mysql -h 127.0.0.1 -u user -p P 33606
Sep 26 18:43:09.000 [warn] Rejecting SOCKS request for anonymous
connection to private address [scrubbed].
thanks for reply but still cant get it to work
root:/var/lib/tor/hidden_service$ proxychains mysql -u user -h TOR.onion database -p
ProxyChains-3.1 (http://proxychains.sf.net)
Enter password:
|DNS-request| TOR.onion
|S-chain|-<>-127.0.0.1:9050-<><>-4.2.2.2:53-<><>-OK`enter code here`
|DNS-response| TOR.onion is 104.239.213.7
|S-chain|-<>-127.0.0.1:9050-<><>-104.239.213.7:3306-<--timeout
ERROR 2003 (HY000): Can't connect to MySQL server on 'TOR.onion' (111)
GRANT ALL ON Databasename.* TO 'user'#'127.0.0.1
getting some error in console phpmyadmin SQL error
i m prety new to this any help is appreicated
mysql workbench works fine on localhost but when trying to add the onion instead of localhost it dosent work:******
Any suggestions thanks
Change your interface to 0.0.0.0 so external connections can happen (bind-address=0.0.0.0 in my.cnf or equivalent)
GRANT access to the external IP in MySQL: GRANT ALL ON <DB>.* TO '<user>'#'<external_ip>';

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.

connect to mysql database server in Windows from Vagrant box

I installed mysql server 5.6, and I can connect to it using mysql workbench, but I'm wondering if I can connect to it from Vagrant box, and I tried the following command, but failed:
vagrant#sdi03:~$ mysql -h 127.0.0.1 --port=3366 -u root -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
Note that I purposely run the mysql server on port 3366 instead of 3306, because I have another mysql server running on Vagrant box on port 3306.
I'm using success connect to ip adress of my windows, it's 192.168.1.55
mysql -u konst -p -h 192.168.1.55
PS I can't connect with root, i create new mysqluser konst with admin's rights

Connect to MySQL via ssh tunnel to localhost

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