Remove new duplicates from any sql table

DELETE FROM yourTable WHERE id NOT IN (SELECT MIN(id) FROM yourTable GROUP BY anotherColumn) If you want to remove older rows, use the following: DELETE FROM yourTable WHERE id NOT IN (SELECT MAX(id) FROM yourTable GROUP BY anotherColumn)

July 28, 2021 · 1 min · Harshvardhan Malpani

How to update customer password in Magento 2 database?

UPDATE `customer_entity` SET `password_hash` = CONCAT(SHA2('SaltPASSWORD', 256), ':SALT:1') WHERE `entity_id` = 7615; Please note that if SPJ9WIp7 is the salt and User’s password is 7qLzX33ETxYE, the following will be your query: UPDATE `customer_entity` SET `password_hash` = CONCAT(SHA2('SPJ9WIp77qLzX33ETxYE', 256), ':SPJ9WIp7:1') WHERE `entity_id` = 7615; 7615 is the customer id

June 12, 2021 · 1 min · Harshvardhan Malpani

How to export multiple selected tables in PMA phpmyadmin (but not all tables)

Click on export, and choose “custom” export method. Lets say you want to export first 20 tables only. Open chrome or browser console [ctrl+shift+j], enter the following: $("input[name='table_data[]']").slice(0,20).click(); For next 20, use 20,50 as arguments in slice function used above.

May 25, 2021 · 1 min · Harshvardhan Malpani

Where are customizer settings stored in db for wordpress theme?

How to clone customizer settings in child theme from parent theme? The customizer data is stored in table wp_options under option_name theme_mods_THEME-NAME you can view all such settings via the following query: SELECT * FROM `wp_options` WHERE `option_name` LIKE "theme_mods_%" In some cases, you just want to use parent theme’s settings in newly added child theme. If that is your case too, use the following queries to utilize and close those settings for your child theme also. ...

May 6, 2021 · 1 min · Harshvardhan Malpani

Fixing broken “screen options” in wordpress site

SELECT * from wp_usermeta where `meta_key` like 'edit_%_per_page' So probably you chose “Number of items per page” as 1000 or 200 and now the page doesnt load anymore because your database ran out of memory. If that is the case, run the above query on phpmysql or any other way, edit the numbers and fixed!

January 18, 2021 · 1 min · Harshvardhan Malpani

How to solve MySQL server gone away error Maria Db update on cPanel and WHM?

This is related to new MariaDb upgrade from 10.1.41 to 10.1.42 and also for servers which were updated from 10.2.27 to 10.2.28 Go to solution ( Special Thanks to @Valetia ) You will see errors in following formats/messages: No file or input found MySQL Server has gone away Connection to MySQL Server failed sqlstate[hy000]: general error: 2013 lost connection to mysql server during query General error: 2006 MySQL server has gone away ERROR 2006 (HY000): MySQL server has gone away ERROR 2013 (HY000): Lost connection to MySQL server during query Log files (/var/lib/mysql/$hostname.err) will have or can have any of these errors: ...

November 6, 2019 · 1 min · Harshvardhan Malpani

How to change attribute dropdown type to multi-select in Magento 2?

Short Answer: Not possible via Magento2 Admin Backend. Solution: You need to update eav_attribute table and edit information about backend_source, frontend_input etc. Simple query for that is: UPDATE `eav_attribute` SET `backend_model`="Magento\\\Eav\\\Model\\\Entity\\\Attribute\\\Backend\\\ArrayBackend", `backend_type`="varchar", `frontend_input`="multiselect", `source_model`=NULL WHERE `attribute_id`=YOUR_ATTRIBUTE_ID_INTEGER LIMIT 1 Replace YOUR_ATTRIBUTE_ID_INTEGER with your attribute_id like 355 Reference: https://stackoverflow.com/a/57701845/2229148

August 29, 2019 · 1 min · Harshvardhan Malpani

How to disable products in Magento2 which dont have any gallery image?

UPDATE `catalog_product_entity_int` SET `value`=2 where `entity_id` in (SELECT a.`entity_id` FROM `catalog_product_entity` AS a LEFT JOIN `catalog_product_entity_media_gallery_value` AS b ON a.entity_id = b.entity_id LEFT JOIN `catalog_product_entity_media_gallery` AS c ON b.value_id = c.value_id WHERE c.value IS NULL) and `attribute_id` = 96 It is SQL query Assumption: value=2 means disable and value=1 means enable attribute_id=96 means “status” attribute References: https://gist.github.com/tegansnyder/8464261#gistcomment-2910808 https://magento.stackexchange.com/a/83033/32283

August 22, 2019 · 1 min · Harshvardhan Malpani

How to wipe all the tables and data in MySQL? Clean whole database

SET FOREIGN_KEY_CHECKS = 0; SET GROUP_CONCAT_MAX_LEN=32768; SET @tables = NULL; SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables FROM information_schema.tables WHERE table_schema = (SELECT DATABASE()); SELECT IFNULL(@tables,'dummy') INTO @tables; SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables); PREPARE stmt FROM @tables; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET FOREIGN_KEY_CHECKS = 1; Will not work via phpmyadmin or any script. this has to be run in cmd/terminal Quick Command wget https://gist.githubusercontent.com/harshvardhanmalpani/e670a8de7aa81673364dd48f125cb9ac/raw/ce04b319bf1594d148d3346e1474119fe1cd1b3f/flushdb.sql mysql -hYOUR_DATABASE_HOSTNAME -uYOUR_DATABASE_USER -p YOUR_DATABASE_NAME < flushdb.sql *Source:* https://gist.github.com/harshvardhanmalpani/e670a8de7aa81673364dd48f125cb9ac

August 3, 2019 · 1 min · Harshvardhan Malpani

How to reverse the ids in a mysql table column without breaking primary key constraint?

Let me explain the problem scenario: Let us assume we have a table with 4 columns in it out of which 1 is PRIMARY column and rest 3 contain some data. What we want to do is to reverse the primary key IDs for that data keeping the rest of data intact. It is like shifting the first row to end and moving last row to starting. Initial Data id name email anything 1 jacob whatever how to reverse 3 nathan whosoeverisnathan ids in mysql table column 4 jagmohan idontknowjagmohan without breaking 8 monica iamsexy primary key constraint 9 batman idontexistinrealworld i am batman Data after update id name email anything 9 jacob whatever how to reverse 8 nathan whosoeverisnathan ids in mysql table column 4 jagmohan idontknowjagmohan without breaking 3 monica iamsexy primary key constraint 1 batman idontexistinrealworld i am batman Dude, you are just reversing the column, what is so tough in this? So, this seems simple to reverse an array if isolated by key “id“. But you have to understand that this column is the primary key. So if you run a command to change id for “jacob” to “9“. It will give you error: “Duplicate entry for id 9“ ...

June 1, 2019 · 2 min · Harshvardhan Malpani