Using the MySQL CLI client.
$ mysql -u <user> -p
mysql> use <your-database>
mysql> DELETE FROM `wp_posts` WHERE `post_type` = "attachment"
Notice that I'm using -u
and username, but in -p
I'm not setting anything. MySQL will ask you for your password.
And if you're trying to use it inline, you can use
$ mysql -u <user> -p <your-database> -e "DELETE FROM `wp_posts` WHERE `post_type` = 'attachment'"
Here, notice that I'm using also -e
argument. It stands for execute.
Pro tip
In MySQL client you can use:
mysql> show databases;
if you want to view all dabatases in your server. And you can use:
mysql> use <database>;
mysql> show tables;
if you want to view all tables into a database.
I'm using $
and mysql>
as prompts, $
means your Linux terminal, and mysql>
, MySQL client.
mysql -u root -p
.username
andpassword
Eg:mysql -uroot -p
then once loged in select your data base usinguse <yourdatabasename
then you can run this command.DELETE FROM {databasename}.wp_posts WHERE
post_type` = "attachment"`