How to update a table if a table exists with MySQL information?

I have a broken mysql database, and I have another good witch with all tables and columns. How can I import only missing information into a broken database, is the witch in a good database? I mean tables, columns, and values โ€‹โ€‹that are not saved.

I exported a good database, and when I try to import into a broken database, I get: # 1060 - Duplicate column name 'id_advice'

so I need to skip if repeating elements and continue adding only info witch does not exist

-1
source share
2 answers

You can use mysqldump. There is a choice to use the data.

mysqldump -uYourUserName -p=YourPassword databasename --no-data --routines > "dump.sql" 

You can import the table. There are also various use cases for create if they do not exist or if they do not exist, so you can customize them for your needs. I recommend downloading the Mysql Workbench, it is easy to do with this tool.

Information about mysqldump http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

+1
source

You can use "IF EXIST" in your SQL statement.

You get every record / table / whatever you want with PHP or another programming language.

Then you will create the following statement as follows:

IF NOT EXISTS (SELECT what-you-want FROM BrokenTable WHERE some-test=some-value) INSERT INTO ClearTable(value, that, you, need, to, insert);

I hope I helped you.

-1
source

Source: https://habr.com/ru/post/1200709/


All Articles