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.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
Use below query to delete category by id from mysql
delete from catalog_category_entity where entity_id= category_id;
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?