How to remove all tables from MySQL Database?

Connect to your mysql host and select the database to be used
example: use notfavoritedb; where notfavoritedb is your database name, and then enter the sql commands given below:

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;
exit;

Reference: StackOverflow

[Forgot Password] [Can’t Log In] How to reset WordPress admin password without sending reset email?

So, admit it. We put really strong passwords and then we forget them.
And you end up being locked out of your own website.

So here is how you can reset it quickly.
Go to your hosting control panel and then go to phpMyAdmin if available.

Look into the database which is being used for your wordpress installation and click on Users table

Inside users table, find the row responsible for your admin account. (check the user_nicename column for username match)
and Press edit.

On the editing screen, put your new password again the column password and Choose MD5 in left column FUNCTION

Now scroll down and save this password.

And that’s it. Go to your domain / wp-admin path and login with the new password you just saved.

What to do if you dont have phpMyAdmin?

You gotta have some kind of access to MySQL, so connect to it using the credentials inside wp-config.php file

Use the following command after replacing your details:

UPDATE `wppl_users` SET `user_pass` = 'e0a8aa81eb1762d529783cf587f6f422' WHERE `wppl_users`.`user_nicename` = 'admin';

If you remember the email address only, use:

UPDATE `wppl_users` SET `user_pass` = 'e0a8aa81eb1762d529783cf587f6f422' WHERE `wppl_users`.`user_email` = '[email protected]';

The above command will set your password to abcd@1234. After this command you can login to wordpress admin panel and then reset your password to anything you want. Or use md5.cz to generate md5 for any password string and replace it with e0a8aa81eb1762d529783cf587f6f422

Do NOT forget to replace “wppl_” with your table prefix (stored in wp-config.php file)

MySQL error 1449: The user specified as a definer does not exist

Why this error happens?

Most of the times, reason is that your database dump through command line or PhpMyAdmin or even other libraries can have SQL’s Definer statements. Now, as per MySQL’s Official Documentation:

The DEFINER clause specifies the MySQL account to be used when checking access privileges at routine execution time for routines that have the SQL SECURITY DEFINER characteristic.

MySQL Reference Manual v8.0

Solution: MySQL mysqldump create a safe backup to ensure no corruption

Use the following command to create backup of your mysql database. Put the command in terminal

mysqldump -hHOST -uUSERNAME -p DATABASE_NAME | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > BACKUP_NAME.sql

With gzip compression > backup

mysqldump -hHOST -uUSERNAME -p DATABASE_NAME | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip > BACKUP_NAME.sql

Reference: https://stackoverflow.com/a/9447215/2229148

How to tweak Magento 2 for two letter search in fulltext mode

The problem:

Magento 2 wont return any search results if the search token is 2 letters in length.

Solution:

Alter MySQL conf file. Edit my.cnf file on your server
In CentOS, use command

nano /etc/my.cnf

and add the following lines:

ft_min_word_len=2
innodb_ft_min_token_size=2

Save using CTRL+x and then restart mysqld service.
Now we need to regenerate the index in order to get updated search results. Use the following SQL commands to regenerate:

Don’t forget to replace “jack_db1” with your database name

ALTER TABLE `jack_db1`.`catalogsearch_fulltext_scope1` DROP PRIMARY KEY, ADD PRIMARY KEY (`entity_id`, `attribute_id`) USING BTREE;
ALTER TABLE `jack_db1`.`catalogsearch_fulltext_scope1` DROP INDEX `FTI_FULLTEXT_DATA_INDEX`, ADD FULLTEXT `FTI_FULLTEXT_DATA_INDEX` (`data_index`);
ALTER TABLE `jack_db1`.`catalog_eav_attribute` DROP PRIMARY KEY, ADD PRIMARY KEY (`attribute_id`) USING BTREE;
ALTER TABLE `jack_db1`.`catalog_eav_attribute` DROP INDEX `CATALOG_EAV_ATTRIBUTE_USED_IN_PRODUCT_LISTING`, ADD INDEX `CATALOG_EAV_ATTRIBUTE_USED_IN_PRODUCT_LISTING` (`used_in_product_listing`) USING BTREE;
ALTER TABLE `jack_db1`.`catalog_eav_attribute` DROP INDEX `CATALOG_EAV_ATTRIBUTE_USED_FOR_SORT_BY`, ADD INDEX `CATALOG_EAV_ATTRIBUTE_USED_FOR_SORT_BY` (`used_for_sort_by`) USING BTREE;

References:
https://magento.stackexchange.com/a/157478/32283
https://dev.mysql.com/doc/refman/5.7/en/fulltext-fine-tuning.html

Insert Indian States in Magento Database

Connect to your server’s database using mysql cli or phpmyadmin and use the following query

INSERT INTO `directory_country_region` VALUES 
(NULL,"IN","AP","Andhra Pradesh"),
(NULL,"IN","AR","Arunachal Pradesh"),
(NULL,"IN","AS","Assam"),
(NULL,"IN","BR","Bihar"),
(NULL,"IN","CG","Chhattisgarh"),
(NULL,"IN","GA","Goa"),
(NULL,"IN","GJ","Gujarat"),
(NULL,"IN","HR","Haryana"),
(NULL,"IN","HP","Himachal Pradesh"),
(NULL,"IN","JK","Jammu and Kashmir"),
(NULL,"IN","JH","Jharkhand"),
(NULL,"IN","KA","Karnataka"),
(NULL,"IN","KL","Kerala"),
(NULL,"IN","MP","Madhya Pradesh"),
(NULL,"IN","MH","Maharashtra"),
(NULL,"IN","MN","Manipur"),
(NULL,"IN","ML","Meghalaya"),
(NULL,"IN","MZ","Mizoram"),
(NULL,"IN","NL","Nagaland"),
(NULL,"IN","OD","Odisha"),
(NULL,"IN","PB","Punjab"),
(NULL,"IN","RJ","Rajasthan"),
(NULL,"IN","SK","Sikkim"),
(NULL,"IN","TN","Tamil Nadu"),
(NULL,"IN","TL","Telangana"),
(NULL,"IN","TR","Tripura"),
(NULL,"IN","UK","Uttarakhand"),
(NULL,"IN","UP","Uttar Pradesh"),
(NULL,"IN","WB","West Bengal"),
(NULL,"IN","AN","Andaman and Nicobar Islands"),
(NULL,"IN","CH","Chandigarh"),
(NULL,"IN","DH","Dadra and Nagar Haveli"),
(NULL,"IN","DD","Daman and Diu"),
(NULL,"IN","DL","Delhi"),
(NULL,"IN","LD","Lakshadweep"),
(NULL,"IN","PY","Puducherry");

Inserting into SQL without specifying primary column

If Primary key is set to Auto-increment, there are chances that you would not want to provide its value in insert query.

 

Here is how to do it in MySQL:
INSERT INTO table_name VALUES (NULL, 'column b', 'col c');

Assumption^: The first column is the primary key set to AI

Similarly you can skip columns for other non-required data:
INSERT INTO table_name(col b,col c) VALUES ('column b', 'col c');