How to run mysql command from terminal?

Solution 1:

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

Solution 2:

I think you have forgot your user name for mySQL. so please enter the correct user name and password when you type mysql command. for eg

$ mysql   -u  root   -p 
Enter Password:

Note: Default user name and password is root

Solution 3:

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

mysql -u root -p database_name

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

Solution 4:

Try this:

mysql --host *HOST_IP* --user *USER* --password=*PASSWORD* -D *DATABASE_NAME* -e "DELETE FROM `wp_posts` WHERE `post_type` = "attachment" ;