简体   繁体   中英

Can't connect to remote mysql (with PuTTY and tunnel)

I'm trying to use mysql on a remote Debian server. I have configured PuTTy client with a tunnel:

  • In Session , Host name is the remote IP address , and port is 22
  • In SSH/Tunnels I have source port 3306 and Destination: 127.0.0.1:3306

I click open, type the user name and password to log in to the server.

But at this point I can't use mysql. If I try this with no password:

mysql -u root -p

I get access denied for user 'root'@localhost' (using password: NO)

I am not sure if this is because there really is some password needed or if there is something wrong with the port forwarding - how can I know?

I tried going in to the my.cnf file and change the bind address 127.0.0.1 to the remote address instead, but there was no change. Maybe mysql needs to be restarted for that, but I get access denied when trying to restart it (the same mysql error message).

I can see in the puTTY event log that it says "local port 3306 forwarding to 127.0.0.1:3306" . A bit further down it says "Opening connection to 127.0.0.1:3306 for forwarding from 127.0.0.1:55271" - I don't know what that's about?

How do I know if the issue is with the password or if it's with the " @localhost " part, were there is something wrong with the port forwarding?

You have either forgotten what your root password was, or you never set it up .. Either way you're going to need to set / reset it.

If you have access to ssh (which your post suggests you do), and you have sudo access .. This should be a snap. Issue the following commands:

Stop your MySQl process .. Most Debian systems will be

sudo service mysql stop

Then start MySQL safely without password:

sudo mysqld_safe --skip-grant-tables &

Then log in as root

mysql -u root

Set the password for root

use mysql;
update user set password=PASSWORD("PASSWORD") where User='root';
flush privileges;
quit

Then restart mysql

sudo service mysql restart

At this point, you should be prompted for a password when you issue the command:

mysql -u root -p

Sounds like you do not need a tunnel. By default mysql install will allow access from localhost without password. The ssh session is remote, but mysql session would be local, so you do not need to change bind address.

Unless your Windows IP is public and reachable from Debian and you have installed MySQL client in Windows properly you still have a couple of less complicated options than a tunnel.

Just start ssh and enter sudo mysql and you should be fine, however, depending on your ssh user and mysql user -and his privileges- you would need to adjust the -u and -p parameters.

Have you run the mysql_secure_installation command?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM