Knowledgebase

Portal Home > Knowledgebase > Articles Database > SSH, and a mysql query - help!


SSH, and a mysql query - help!




Posted by Jon12345, 07-17-2012, 10:09 AM
Using Putty, I have managed to log into my hostmonster account using the command line. Now I need to run a mysql query on a database I have there. My database is called mydata and the query I need to run is shown below: Can some kind soul tell me how to do that in Putty? I'm all logged in and ready to type but not sure what to type! Thanks, Jon

Posted by sharedservermgmt, 07-17-2012, 10:24 AM
Hi Jon, Once you are logged into ssh, you need to go into the mysql prompt. usually the command is mysql-uusername -p (replace username with your actual db username and enter the password when it prompts you for the password) on the mysql prompt you will first have to select your database so type use dbname; ( replace dbname with your actual db name and hit return) then type what every query you want to execute. hope it helps.

Posted by Jon12345, 07-17-2012, 10:32 AM
That was very useful. The mysql-uusername -p part. Is it meant to have no space between the - and the u? Is there meant to be two u's?

Posted by sharedservermgmt, 07-17-2012, 10:37 AM
Yes, sorry my bad (no need for space after -u)

Posted by Jon12345, 07-17-2012, 10:40 AM
And there two u's? Or should there be one? I ask because I got an error message when putting my password in saying ERROR 1045 (28000): Access denied for user 'yname'@'localhost' (using password: YES) ...when is should say myname. It cut short the username.

Posted by sharedservermgmt, 07-17-2012, 10:43 AM
I guess you typed

Posted by Mopman, 07-17-2012, 10:43 AM
Just one u - you can put a space if you want to make it clearer, it's -u .

Posted by Jon12345, 07-17-2012, 10:48 AM
You are right sharedservermgmt. Doh!

Posted by Jon12345, 07-17-2012, 10:50 AM
Whoa! It seemed to work? First time I have ever successfully used SSH on a database. Much easier for the future. Thanks guys!

Posted by Jon12345, 07-17-2012, 12:18 PM
My tid field is int(10). If I wanted to delete anything above 3, is this correct? Or should I take the single quotes off the 3?

Posted by sharedservermgmt, 07-17-2012, 12:27 PM
Hi, Its correct as long as you have selected the DB first.

Posted by Jon12345, 07-17-2012, 12:28 PM
Ok, thanks.

Posted by kar1181, 07-18-2012, 07:27 AM
echo 'DELETE FROM `mybb_posts` WHERE `tid` > 3;' | mysql -u -p Type the above without the '<' or '>' characters. I removed the quotes from around the 3, as that can on occasion lead to unexpected behaviour (it could treat the number 3 as a string value, rather than it's absolute integer value).



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read


Language:

Contact us