I want to remove category using MySql Script

So I can delete the category using category ID completely from magento 2 as we did in admin area category section.


Use below query to delete category by id from mysql

delete from catalog_category_entity where entity_id= category_id;
  • Are you sure it delete the category completely from all related tables in database? – Purushotam Sharma Sep 6 '18 at 6:09
  • yes you can check in local it will delete all related data also – Ansar Husain Sep 6 '18 at 6:12
  • yes i did check it its deleting all related data also from catalog_category_entity_int table also – Ansar Husain Sep 6 '18 at 6:16

If you want to remove specific category then instead of SQL you can also do it via Root File.

Just create category-delete.php file on the root folder

See below example:

use \Magento\Framework\App\Bootstrap;


$bootstrap = Bootstrap::create(BP, $_SERVER);

$objectManager = $bootstrap->getObjectManager();    
$state = $objectManager->get('\Magento\Framework\App\State');

$rootCat = $objectManager->get('Magento\Catalog\Model\Category');
$cat_info = $rootCat->load(1832); //1832 is the category ID
echo '<pre>';print_r($cat_info->getData());die('died');

Let me know the above example is helpful or not?

  • Thanks for your answer, but I am looking for Mysql query to delete the category in magento 2 – Purushotam Sharma Sep 4 '18 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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