update mysql from a sql file - mysql

Im new to the php and mysql. I have been coding an auto update script. Everything works fine as I can download the latest version files from my own host which includes of the sql file of mysql. All I want to do an update due to this sql file.
What I want this code to do is;
If there is new tables, add it to the mysql and if we have deleted 1 table it can check and delete the same table from mysql.
But while we are doing this update, we will have so many entries under columns so I dont want it to update the columns which has entries in it. But if this is a column that we have deleted from the source sql file then it will delete it.
If there is new column on the source sql file then it will add that column to the mysql.
Any possibility can help me? Try to find if I can find something similiar but I couldnt see. Thats why I opened a topic here.
Thank you very much

Related

Easy edit and delete row from mysql

I'm not that good at mysql but some of my tables has this line where I can edit and delete the row easy without writing any SQL? How can I make that row inside another table?
You can use any GUI editor like phpmyadmin or the tools which P.Salmon mentioned.
Using GUI editor, you can connect to the database using connection string and you can view tables and see the result which can edited and deleted.

What's SQL equivalent of MySQL SHOW CRAETE TABLE query

I have a remote SQL Server database that I don't want to copy because of it's size. I want to just remotely import it's creation query to duplicate it's structure locally.
I know there was a query for it but lost somewhere my book about it. I ask for name of that query method that I described. If got any questions please don't hesitate to ask.
I found it. It's SHOW CREATE TABLE http://dev.mysql.com/doc/refman/5.0/en/show-create-table.html

Is it possible "Database Synchronization"

I have a problem and not sure if this is possible. My web application has a database and i'm using a mysql workbench and using wamp server.
My web app has a database name healthcare, and if I import again another database with the same tables, etc but addition data. I want the first database to be updated only with new values but not replaced.
Is it possible?
Edit: I searched in the net and other related sources and I manage to set my phpmyadmin "Ignore multiple statement errors". When I import the second database (.sql with same tables but with new data) it does not update the first database but the message is successful. Please help, I'll appreciate any help...
in the past ive searched for tools to do some similar database sync tasks - in my experience ive found that none are free & reliable.
have you tried writing some queries to do this manually?
first thing that comes to mind would be figuring out a key you can use to evaluate each row and determine if you should copy said record from database A to database B.
afterwards you could simply do an INSERT(SELECT)
INSERT INTO healthcare_DESTINATION.table (SELECT * FROM healthcare_SOURCE WHERE some_condition = 1);
obviously this is the simplified version - but i've done something very similar utilizing timestamps (eg only copy rows newer than the newest row in the destination table)
hope this helps

Import some database entries through PHPMyAdmin with overwrite

I exported a couple of entries from a database I have stored locally on my MySQL dbase through PhpMyAdmin and I'd like to replace only those entries on my destination database hosted online. Unfortunately when I try to do so PHPMyAdmin says that those posts already exist and therefore he can't erase them.
It'll take me a lot of time to search for those entries manually within the rest of the posts and delete them one at a time so I was wondering if there's any workaround in order to overwite those entries on import.
Thanks in advance!
A great option is to handle this on your initial export from phpMyAdmin locally. When exporting from phpMyAdmin:
Export method: Custom
Format: SQL
Format-specific options - choose "data" (instead of "structure" or "structure and data")
In Data creation options - Function to use when dumping data: Switch "Insert" to "Update" <-- This is the ticket!
Click Go!
Import into your production database. (always backup your production database before hand just in case)
I know this is an old post, but it actually helped me find a solution built into phpMyAdmin. Hope it helps someone else!
This is a quick and dirty way to do it. Others may have a better solution:
It sounds like you're trying to run INSERT queries, and phpMyAdmin is telling you they already exist. If you use UPDATE queries, you could update the info.
I would copy the queries you have there, into a text editor, preferably one that can handle find and replace, like Notepad++ or Gedit, and then replace some code to change the queries around from INSERT to UPDATE.
See: http://dev.mysql.com/doc/refman/5.0/en/update.html
OR, you could just delete them, then run your INSERT queries.
You might be able to use some logic with find and replace to make a DELETE query that gets rid of them first.
http://dev.mysql.com/doc/refman/5.0/en/delete.html
Check out insert on duplicate. You can either add the syntax to your entries stored locally, or import into a temporary database, then run an INSERT ... SELECT ... ON DUPLICATE KEY UPDATE. If you could post a schema, it would help us guide you better.

Appending rows in a database using toad and excel

Friends, I am using toad for MySQl, and have a huge database ready and validated.
Now i have an excel file which contains data-entries for a particular table. And i am also successfully able to import data into the db using import wizard, mapping the first row header with the column names etc.
But now i have appended a few data entries into it which i wish to insert into the database. However the old values also get selected and hence cause a primary_key_violation exception as the entry already exists! Otherwise a truncate table option is there which i dont wish to use as there may be many files from which i have inserted the data.
I tried my level best but didnt get any solution, atleast in toad for mysql. Please tell me what to do! the solution maybe simple but i need it SOS
An option may be to not append records to that excel file, but create a new excel file with only the new records