On the server, I've got it set up, that the root doesn't need to enter password in order to use mysql (credentials are in ~/.mylogin.cnf). Now I want to connect to the mysql remotely via SSH tunnel and I'm expecting that i won't need to enter the password.

# open the tunnel (I'm using local port 3305 because 3306 is already taken for some reason)
ssh server -L 3305: -N

# now try to connect
mysql -h -P 3305 -u root

But this doesn't work. Error says: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

What am I doing wrong?

  • Are you looking to do this to encrypt the data? If that is the case, Mysql/Mariadb has built in encryption that can be configured Nov 16 '17 at 11:26

You've set up your mysql credentials on a remote server and you're running the mysql client locally.

Please set up an instance of mysql in ~/.mylogin.cnf for localhost at port 3305.


You can also add -p at the end of the command to get a password prompt.


Are you sure that you can open an ssh connection as root? Some Linux distributions restrict root ssh access by default. Check the /etc/ssh/sshd_config file for the lines

PermitRootLogin yes
PasswordAuthentication yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.