Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have the following sql command which I usually run in phpmyadmin by selecting the database, then running it in the command window.

DELETE FROM `wp_posts` WHERE `post_type` = "attachment"

However I've never done this via terminal before. My question is, how do I "point" this command to a specific database and then running it?

Thanks

share|improve this question
    
Try mysql -u root -p. –  Mitch Sep 5 '13 at 6:40
    
How can you run any command without login to MySQL? First in terminal you have to login using your MySQL username and password Eg: mysql -uroot -p then once loged in select your data base using use <yourdatabasename then you can run this command. –  Saur.K Sep 5 '13 at 6:41
    
You can also put the database in front of the table like so: DELETE FROM {databasename}.wp_posts WHERE post_type` = "attachment"` –  Rinzwind Sep 5 '13 at 7:24
add comment

3 Answers

For you to run it from terminal, you need to be logged into mysql first and then you execute your program. The ideal code would be

mysql -u(username) -p(password) (the name of the database) -e "DELETE FROM `wp_posts` WHERE `post_type` = "attachment""

I`m sure this works, hope it helps

share|improve this answer
add comment

Just type the following command in terminal to use mysql interpreter:

mysql -u root -p

Enter your password, then you can run your mysql commands.

Another way is to use:

mysql -u root -p database_name << eof
DELETE FROM `wp_posts` WHERE `post_type` = "attachment"
eof
share|improve this answer
add comment

Okay basically it was "SELECT databasename;" then executing my command.

share|improve this answer
    
You can also specify the database name on the command line, such as mysql -u root -p databasename - enter password when prompted and you are using the database. –  David Purdue Sep 5 '13 at 6:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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