Mysql

Mysql export & import database

Export

mysqldump -u<username> -p database > database.sql
1

Import

mysql -u<username> -p
use <database>;
source database.sql;
1
2
3

Diff between 2 tables sql

You can use this sql request for check data integrity with old table when you have an important update of your code.

First method

SELECT 
	a.id, firstName, a.lastName, 
	b.id, b.firstName, b.lastName
		FROM table1 a
			INNER JOIN table2 b ON a.id = b.id
	WHERE 
		a.firstName <> b.firstName
		OR
		a.lastName <> b.lastName
;
1
2
3
4
5
6
7
8
9
10

Second method

SELECT DISTINCT * 
  FROM (
  	SELECT * FROM ( 
  		SELECT * FROM table1      
  UNION ALL
    SELECT * FROM table2) Tbls
    GROUP BY column1, column2, column3
    HAVING COUNT(*)<2) Diff
1
2
3
4
5
6
7
8
Last Updated: 1/17/2020, 2:26:44 PM