I wish to modify data on my website database and thought I could do it from the command line but it keeps failing. For example:-

website is myweb.co.uk database is mydb port 22

mysql -u myweb -hmyweb.mysql  -P22 -Dmydb

Presumably, I just need to get these three terms right and it should work

  • I think one form would be mysql -u myweb -h 'remote server ip or name' -P 22 -D mydb -p 'password' or mysql -u username -h host -P 22 -p and remote must accept remote access – George Udosen Nov 24 '18 at 9:59
  • The resolution will be very easy. The problem with providing the resolution is that you didn't provide enough information. Please edit your question and add the error output. – L. D. James Nov 24 '18 at 14:43

First of all, port 22 is used for ssh, not mysql. In addition, its not common to run mysql visible on the internet.

But, if you do have ssh access, you can work around this, by tunneling mysql trough ssh.

In one terminal, run

ssh -L 3306:localhost:3306 example.com

where example.com is the remote ssh server. This creates a tunnel, between port 3306 locally, and on the remote end. This is encrypted and transported via ssh, so any secrets (passwords and queries) are encrypted while transported over the internet.

In another terminal, you will be able to run

mysql -h localhost --protocol=TCP -u username -p

--protocol=TCP is required, as by default mysql will connect to the socket connection on localhost, but this is unavailable, as mysql is not running locally. This connects to the ssh-tunnel set up previously.

  • Thanks for that. I can connect with ssh in one terminal but from the second terminal I get:- ERROR 1045 (28000): Access denied for user . the command was:- mysql -h localhost --protocol=TCP -umyweb.co.uk -p – bill-lancaster Nov 24 '18 at 11:03
  • Sorry, the host shown in the error message was 'myweb.co.uk'@'localhost' – bill-lancaster Nov 24 '18 at 11:09
  • Did you enter a password? – vidarlo Nov 24 '18 at 11:17
  • Yes, but you're right because there are several passwords associated with the website, but I tried them all. – bill-lancaster Nov 24 '18 at 12:27
  • Use the same credentials as for MySQL in the application you have... – vidarlo Nov 24 '18 at 12:57

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.