Mysql and SSH

I’m trying to activate a file (ubicomp.sql) in my home directory (this file will create a sql table). but when i type this in the SSH:

mysql -u’myUsername’ -p’myPassword’ tableName < ubicomp.sql

…this error come up:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

what am I doing wrong?


you have to specify your host name to connect to your mysql database. Check out this kabase article it gives you an example of how to do it (in color)


thanks matttail,

The links is very helpful but I have a feeling I’m placing the .sql file in the wrong place, cuz it is not getting dumpped.
I’m putting it in my home directory. I don’t know where else I can put it. is it the right location for it?
sorry, i’m kinda new to the whole DB world.


I’m not very familiar with this my self, but by the error you are getting I can tell that it is complaining because it can’t connect to your database at ‘localhost’ which is the linux defult. So, like the article describes, fill out the host name (the one you created when you set up the databae in your panel) and you’ll be good to go.

If you specify your host name it should get dumped into the right place becuase you can only have one database per hostname.

If the file you are trying to dump isn’t very large you might also be able to use PHP my admin. (but there are specific files size limits that prouduce a confusing error message when you encounter it) you can connect to that by going to your host name in a browser.


sorry i wasn’t clear enough. I actually did add the host name and it did connect to mysql. it gave me this long commands list or something when it connected but the tables that I specify in the text file were not created. That’s why I feel that maybe the txt file should be placed elsewhere and not in my home directory.

anyway thanks for your help.

OK so I ended up doing it through myadmin. by clicking on the database name on the left nave and then clicking SQL then browsing for the file on my computer and dumping it. It was easy.
I’m a bit annoyed not to be able to do it through ssh though.


It does work through the shell. Without seeing the file and/or at least the error message, and the offending line it’s impossible for us to diagnose. The file may have been transfered wrong it may have been compressed, it may have been a Lynux/DOS format problem.

-Jason - Home Page
MP3Mystic - Personal Streaming Music server.
(Links to my sites are always appreciated)


Ah! I just realized what it is. I think it’s a chmod prob. I just checked and found it wasn’t 755.
well, i didn’t try to run it cuz i got these tables in sql already but i’m guessing that was the problem.

The permissions of the file won’t make any difference as long a your user account can read it fine (and I’m assuming you could). Also, the location of the file doesn’t make any difference as long as you reference it with the correct path. In your example, you were referencing the file in your current shell directory which defaults to your home directory when you first log in so that was probably fine as well.

Note that where you put tableName in your example it should be databaseName instead. You specify the database you want to inject the SQL code into and the SQL code should specify the table information itself.

You’ve already figured out your problem, but perhaps this will help others!

  • Dallas
  • DreamHost Honcho