1

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.

1

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
0

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:

<?php
use \Magento\Framework\App\Bootstrap;

include('app/bootstrap.php');

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

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

$rootCat = $objectManager->get('Magento\Catalog\Model\Category');
$cat_info = $rootCat->load(1832); //1832 is the category ID
$cat_info->delete();
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.