mySQL - populating the tables in EER diagram and generating .sql file - mysql

I'm newer to mySQL and I'm having some difficulty generating a .sql file with insert statements:
I have made an EER diagram, forward engineered this diagram to generate the database, then used the insert statement in the terminal to insert values into my tables.
Now I'm having difficulty bringing this new/updated database back to mySQL workbench and create a .sql file of the whole thing (schema+ what was inserted into the tables).
I had no luck looking here or searching videos on uTube. Any help/links is highly appreciated to show the step by step walk through.

if you have logged into MySQL workbench then tried going to the schema tab (on the left) and hitting the two arrows that make a circle -- that should populate any tables that you've inserted into terminal. if not you can manually add the script file using one of the button on the top left "open a SQL script file". Check out this tutorial for more info.

Related

How do I populate a mysql workbench models inserts from a mysql script?

I cannot find a function that reverse engineers a mysql create AND insert script and places the inserts into the tables created inside the model.
When I go to Import->Reverse Engineer MySQL Create Script it does not place the insert statements into the table inserts.
The only option I found that was similar was import records from an external file, but it defaults to CSV and if I change the file type to All Files it does nothing when I open a .sql file with multiple inserts inside of it.

How To Restore the records in mysql table which was deleted unfortunately

I deleted records in a MySQL table two days ago. Can you please help me to get back these records. I don't know how to repair the MySDL table.
Please help me to get back the deleted data and mention some way to create a backup for my MySQL database.
There's no "magical" way to restore deleted data, so :
To create a backup, you simply have to export the whole database in a file. This can be done easily with any database manager. Here is how to do it with PHPMyAdmin :
Click on your database (left pane)
Click on Export (top of the page)
Click on Go for a quick and full export
Keep the generated file in a safe place (ie. not in your website folder)

What Inserts tab does in MySQL Workbench EER Diagram Table Editing?

I needed to insert some initial (default) data into a new database and I found this Inserts tab on MySQL Workbench EER Diagram table editing form
My assumption was that I can use it to insert initial (default) data that will get propagated to the database during synchronization (not sure how it will get merged with any existing data in the database though...). I added couple rows and synced model with an empty database, but no data was inserted.
So, my question is what this Inserts tab is for on the Table Editing screen?
I use MySQL Workbench 6.
P.S. If somebody can also point to an easy way to insert initial (default) data (except simply running a SQL script) I will appreciate it.
Thank you.
The data added on the INSERTs page is indeed thought to be like an initial set of (test)data. It doesn't consider existing data however. I think it is also only used if you do forward engineering, not on synchronization.
Other ways of inserting data always involve an SQL script, that's what the (text) API is about for SQL servers. But you can add scripts to your model too (see the overview page). They are not run automatically, however.

MySQL Workbench Inserts

I am using MySQL Workbench 5.2.28 for designing my database schema. I need to insert default data into some tables which can be done using the "Inserts" tab. However, it seems like it only allows entering data manually, one row at a time. I have an OUTFILE with several hundred rows that I would like to insert.
Is this possible with MySQL Workbench? Would creating separate MySQL scripts for importing default data be a better approach?
I am now using separate sql scripts for inserting my data as there doesn't seem to be an easy way to add bulk inserts to MySQL workbench.
Generate CSV (quoted if you have comas in values) in Excel for example, then just copy/paste all rows into workbench via 'inserts' tab for each table in model.
Works with Workbench version 5.2.40.
In the MySQL Workbench Version 6.2 you will find a Import Button which alows you to Import Inserts from a CSV File with "," as delemiter.
You are right there is no way I know doing this automatically. The only thing you can do is to generate all your inserts scripts in a single time by doing a forward engeniering and then by copying the insert statements at the end of the generated script (You must check the option "Generate INSERT statements").

question about MySQL database migration

If I have a MySQL database with several tables on a live server, now I would like to migrate this database to another server. Of course, the migration I mean here involves some database tables, for example: add some new columns to several tables, add some new tables etc..
Now, the only method I can think of is to use some php/python(two scripts I know) script, connect two databases, dump the data from the old database, and then write into the new database. However, this method is not efficient at all. For example: in old database, table A has 28 columns; in new database, table A has 29 columns, but the extra column will have default value 0 for all the old rows. My script still needs to dump the data row by row and insert each row into the new database.
Using MySQLDump etc.. won't work. Here is the detail. For example: I have FOUR old databases, I can name them as 'DB_a', 'DB_b', 'DB_c', 'DB_d'. Now the old table A has 28 columns, I want to add each row in table A into the new database with a new column ID 'DB_x' (x to indicate which database it comes from). If I can't differentiate the database ID by the row's content, the only way I can identify them is going through some user input parameters.
Is there any tools or a better method than writing a script yourself? Here, I dont need to worry about multithread writing problems etc.., I mean the old database will be down (not open to public usage etc.., only for upgrade ) for a while.
Thanks!!
I don't entirely understand your situation with the columns (wouldn't it be more sensible to add any new columns after migration?), but one of the arguably fastest methods to copy a database across servers is mysqlhotcopy. It can copy myISAM only and has a number of other requirements, but it's awfully fast because it skips the create dump / import dump step completely.
Generally when you migrate a database to new servers, you don't apply a bunch of schema changes at the same time, for the reasons that you're running into right now.
MySQL has a dump tool called mysqldump that can be used to easily take a snapshot/backup of a database. The snapshot can then be copied to a new server and installed.
You should figure out all the changes that have been done to your "new" database, and write out a script of all the SQL commands needed to "upgrade" the old database to the new version that you're using (e.g. ALTER TABLE a ADD COLUMN x, etc). After you're sure it's working, take a dump of the old one, copy it over, install it, and then apply your change script.
Use mysqldump to dump the data, then echo output.txt > msyql. Now the old data is on the new server. Manipulate as necessary.
Sure there are tools that can help you achieving what you're trying to do. Mysqldump is a premier example of such tools. Just take a glance here:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
What you could do is:
1) You make a dump of the current db, using mysqldump (with the --no-data option) to fetch the schema only
2) You alter the schema you have dumped, adding new columns
3) You create your new schema (mysql < dump.sql - just google for mysql backup restore for more help on the syntax)
4) Dump your data using the mysqldump complete-insert option (see link above)
5) Import your data, using mysql < data.sql
This should do the job for you, good luck!
Adding extra rows can be done on a live database:
ALTER TABLE [table-name] ADD [row-name] MEDIUMINT(8) default 0;
MySql will default all existing rows to the default value.
So here is what I would do:
make a copy of you're old database with MySql dump command.
run the resulting SQL file against you're new database, now you have an exact copy.
write a migration.sql file that will modify you're database with modify table commands and for complex conversions some temporary MySql procedures.
test you're script (when fail, go to (2)).
If all OK, then goto (1) and go live with you're new database.
These are all valid approaches, but I believe you want to write a sql statement that writes other insert statements that support the new columns you have.