cancel
Showing results for 
Search instead for 
Did you mean: 

How do I delete a category in phpmyadmin

SOLVED

How do I delete a category in phpmyadmin

Gear category does not show in admin, but shows on frontend.

 

Found this command and want to be sure it is the correct command:

delete from catalog_category_entity where entity_id= category_id;

How do I find out what the category id is?

 

ran command and got Error

SQL query:

delete from catalog_category_entity where entity_id=3 category_id

 

MySQL said: 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'category_id' at line 1

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How do I delete a category in phpmyadmin

Hello @Sheba 

 

may be you assign title store wise so switch store wise and check it

 

regarding to category:-

select * from catalog_category_entity_varchar where value like '%gear%'

select * from catalog_category_entity_text where value like '%gear%'

by using you will find out category id
 and run below query 

delete from catalog_category_entity where entity_id=3

where 3 will be found from above two query.

 

if works then mark as a solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

View solution in original post

9 REPLIES 9

Re: How do I delete a category in phpmyadmin

Hello @Sheba 

 

Please use the below script to remove the category:

 

<?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(3); //3 is the category ID
$cat_info->delete();
echo '<pre>';print_r($cat_info->getData());die('died');

Hope it is helpful.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: How do I delete a category in phpmyadmin

Hi @Sheba,

The correct query will be :

delete from catalog_category_entity where entity_id=3

Make sure that "3" is the correct category id.

If you are using Flat tables then do the reindex once as well.

php bin/magento indexer:reindex

I hope it will help you!

Re: How do I delete a category in phpmyadmin

where do I put this code?

Re: How do I delete a category in phpmyadmin

Hi @Sheba,

The code which shared by @Meetanshi,  you can create a new php file on the Magento root folder.

Then you hit that file from browser.
If you want to delete directly from database, then then query which I have shared also work for you.

I hope it will help you!

Re: How do I delete a category in phpmyadmin

I posted the error I got when I ran that command

Re: How do I delete a category in phpmyadmin

@Sheba 

Have you tried the query which I have shared with you?

delete from catalog_category_entity where entity_id=3

Re: How do I delete a category in phpmyadmin

NO. I asked where to use the code you sent.

Re: How do I delete a category in phpmyadmin

Hello @Sheba 

 

may be you assign title store wise so switch store wise and check it

 

regarding to category:-

select * from catalog_category_entity_varchar where value like '%gear%'

select * from catalog_category_entity_text where value like '%gear%'

by using you will find out category id
 and run below query 

delete from catalog_category_entity where entity_id=3

where 3 will be found from above two query.

 

if works then mark as a solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How do I delete a category in phpmyadmin

Thank you so much. Always the right answers.