Mysql

Mysql export & import database

Export

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

Import

mysql -u <username> -p
use <database>;
source database.sql;
Sh

Diff between 2 tables sql

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

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

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
SQL

MarquandT

Ethical Hacker ~ Web Developper ~ Hosting Provider ~ Crypto Enthusiast ~ Automation Expert Bitcoin donation: 32Uu4NKGnxSPC7UukYXVyRHwbppbQpKVki

Comments

You must login to send a comment.