Skip to content

MySQL

Take a backup of the production database using the mysqldump command. Replace with the name of your production database, and with the desired name for your backup file:

mysqldump -u root <prod_db_name> > <backup_file.sql>  

Import the backup file into the test database using the mysql command:

mysql -u <username> <test_db_name> < <backup_file.sql>

Show database

mysql -u root -e "show databases;"

MySQL find table

Provide password for usermysqlconnect that has access to MySQL database:

mysql -u usermysqlconnect -p
SHOW DATABASES;
USE namedb;
SHOW TABLES LIKE '%wordintablename%';
SELECT * FROM tablename WHERE columname LIKE 'textincolumn%';

MySQL count records with the same email

SELECT contact_email, COUNT(*)
FROM profile_profile
GROUP BY contact_email
HAVING COUNT(*) > 1;

MySQL find empty email

SELECT * 
FROM profile_profile
WHERE contact_email = '';

MySQL set NULL email for empty email

UPDATE profile_profile
SET contact_email = NULL
WHERE contact_email = '';