help me restore a database - mysql

I have a database backup that I'm trying to load so that I can extract some historical averages. I think it was a MySQL database, but with some syntax adjustments I was able to create the one and only table I need in Oracle 11g. However, I'm having problems with the INSERT INTO portion of the backup. Basically, some of these text fields were taken directly from fields on our website, and whenever users entered an apostrophe, it messes up everything that follows. Finding all instances of this would take a very long time...
Is there any way to handle this?
Also, all the text in SQL Developer runs horizontally on 2 or 3 rows. Is there any way to fix that? It makes for a lot of side-scrolling instead of vertical scrolling.

Use phpMyAdmin to reload the database into mySQL.

Related

PHPMyAdmin put the most recent database

I'm wondering if there is any better way than going through the tables one by one adding the columns missing when some fields/tables needs to be added because of the most recent changes in the app?
For example, I'm working at the localhost and when I finish doing the new version of my app, I will put all the files into my FTP and, sometimes, I have done, in my local database, changes and so it means that I also need to update my database at my server.
There's any better way to add/edit the columns/tables without changing the info? Some of the columns are also deleted, etc.
Hopefully you've thought your database design through so that making changes to the structure is a rare occurrence. If you're making regular changes to the number of columns or adding tables, it's likely a sign that you haven't normalized your database structure sufficiently.
Anyway, I'd script it as an SQL file that you deploy (which you can then run through phpMyAdmin or the command line or any other means you prefer to execute SQL queries). This has the added advantage of being something you can easily duplicate across your development and production databases, send to customers, and if you wish store in version control so you know when exactly you made the changes to the database.
This way, you'll end up with an SQL file that has a couple of statements like
ALTER TABLE `foo` ADD `new` INT NOT NULL ;
or something similar.
As for how you'd make the file, probably the easiest way is just copying and pasting the generated SQL statement from phpMyAdmin after modifying the table -- the SQL code used to make the change is shown near the top of the screen on the next page. You can copy and paste that to a new text file to create your SQL file. You may wish to add the first line
use `baz`;
using your database name instead of "baz". That way you don't have to specify on import which database the changes are meant for.
Hope this helps.

MySql weird behavior on databases with the same name

I have a database that I create through phpMyAdmin. Then I update it by creating tables in it via a script. All fine til now, then I use it. Two days later I drop this database altogether. Then I create another one with a different name, create something in it as well. Drop it too. Then I create a database with the same name as the first one, again creating tables in it. I leave it that way to find out that the next day I login I get the first database (with its contents) rather than the thing that I expected.
This type of weird behaviour happens no matter how you turn it. The same name is not the problem I think since I know it can happen with databases that carry different names. (I've tried it)
Basically it's like this thing forgets about it's state. What is happening? Any ideas?
This thing is driving me nuts since I can't do anything without fearing that I lose data.
I'm using windows with Zend Server.
I am NOT accidentally dropping tables or something like that.
EDIT: It seems that an immediate restart does not have any effect (meaning it keeps things as is, the random changes happen only after a certain period of time (more than a day)
Databases are stored on disk as folders containing:
one file describing the structure of each table
another file containing all of the tables' rows
one file for each index/key you define
some files (just allocated blocks) intended to allow storing large data such as text-columns or blob-columns which do not reside in the tables' rows (the rows only have a reference to where the blob resides).
When dropping a table the OS deletes some files. When dropping a database the OS deletes a folder.
It is possible (though very unlikely) that the database folder wasn't correctly deleted in the first place -- be it a permission issue on how you installed your server or a server bug or a phpMyAdmin bug.

Create and use data tables in netbeans

I have a table with:
vegetable name -- calcium contents -- Potassium contents -- vitamins -- fibers-- price (etc)
Let's say there are 5 entries (rows) in the table and I have to initially feed the data manually, like a first one time data feeding.
My requirement/problem is:
On a GUI when I select a vegetable name from a drop down menu I should get the contents displayed and then all of them should get added to get final score except the 'price'.
On the GUI if I select the 'vegetable name' and any one of the other 'property' (like 'fibers') then only that value should be displayed. e.g query-- spinach, fiber ? answer spinach-fiber = 20 unit., or spinach-vitamins = 40units etc.
I also want help in what type of database I should use here and how to populate the data for accessing it in the program later on. I believe its a simple data table of small size so what is the most efficient way of doing this?
Specific help with code will be of great help as I am absolutely new to java and netbeans.
Also, can I have a separate GUI for adding/appending further data from user in the same table? If yes, how is it done please?
I am using Netbeans 7.1.2.
After some search I got info about MySQL datatables in netbeans. (http://netbeans.org/kb/docs/ide/java-db.html)
I have created and made entries in the table but do not know how to access them for my questions 1 and 2 above. Also not sure if it is the right data table that I should be using for such simple use.
Seems like you need to learn about JDBC first. Just to clarify connecting to a database inside the IDE is generally used for more development/administrative type duties and you WONT be using it in your Swing program.
So for example you need to load a set of test data to test a function you would typically use either the MySQL workbench or load it via the IDE. However you will not connect this way when you run a program.
What you need to learn is how to connect to a database from a front end, how to execute a query and how to display the query. At this point I would suggest getting a couple of books on JDBC or even doing a google search for JDBC introduction tutorials.
Get to learn JDBC without thinking too much about the front end. Do a couple of examples and then once you are familiar with JDBC then work on the front end.
You might want to spend time on learning basic SQL as well as this will be needed to properly query your database. I am assuming you have not done any SQL.
Here is a reasonably good link to a site with information that you might want to use http://infolab.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html
Just remember the IDE(Netbeans) basically uses JDBC to allow you to connect and manipulate data. So while it is based on JDBC the IDE database explorer is NOT the tool you will be using when programming your swing interface.

Rearrange Column Order in Navicat

in navicat you can arrange the order of the columns but i have yet to find a way to sync the changes with the database. i saw a similar question here -> Rearrange column order in Sqlyog but haven't found anything similar in navicat. i have many tables that need to be fixed for export to excel and the order is important in the readability/presentation. typing out sql code for each move would be way too tedious. thanks in advance.
you can't do it in navicat , you have to run a sql query for that purpose
You can reorder columns using SQLyog. To change the sequence of columns in a table, select the table in the Object Browser and select Table -> More Table Operations -> Reorder Column(s) (Ctrl+Alt+R) from the popup menu.
Select any column and click Up or Down button to move the column up / down. Having re-sequenced the columns, click Re-Order to save the table with changed structure. The column data in the table gets re-arranged accordingly.
This is a really old question i Stumbled on going to answer just in case someone needs
Navicat provides the ability to change the column order in a table by using the design table feature
Either right click on the table name or press ctr-d on the top of the screen there are arrows to move a column up or down
By pressing on the SQL preview tab on the top you can actually see the ALTER TABLE statements navicat is going to run
You can also copy-paste this Statement and run on any other test database you may have or as a git migration
Its a good idea to always read the SQL Preview as some times Navicat may use DROP statements and you would want to take a backup before something like that

MySQL to SQL Server transferring data

I need to convert data that already exists in a MySQL database, to a SQL Server database.
The caveat here is that the old database was poorly designed, but the new one is in a proper 3N form. Does any one have any tips on how to go about doing this? I have SSMS 2005.
Can I use this to connect to the MySQL DB and create a DTS? Or do I need to use SSIS?
Do I need to script out the MySQL DB and alter every statement to "insert" into the SQL Server DB?
Has anyone gone through this before? Please HELP!!!
See this link. The idea is to add your MySQL database as a linked server in SQL Server via the MySQL ODBC driver. Then you can perform any operations you like on the MySQL database via SSMS, including copying data into SQL Server.
Congrats on moving up in the RDBMS world!
SSIS is designed to do this kind of thing. The first step is to map out manually where each piece of data will go in the new structure. So your old table had four fields, in your new structure fileds1 and 2 go to table a and field three and four go to table b, but you also need to have the autogenerated id from table a. Make notes as to where data types have changed and you may need to make adjustments or where you have required fileds where the data was not required before etc.
What I usually do is create staging tables. Put the data in the denormalized form in one staging table and then move to normalized staging tables and do the clean up there and add the new ids as soon as you have them to the staging tables. One thing you will need to do if you are moving from a denormalized database to a normalized one is that you will need to eliminate the duplicates from the parent tables before inserting them into the actual production tables. You may also need to do dataclean up as there may be required fileds in the new structure that were not required in the old or data converstion issues becasue of moving to better datatypes (for instance if you stored dates in the old database in varchar fields but properly move to datetime in the new db, you may have some records which don't have valid dates.
ANother issue you need to think about is how you will convert from the old record ids to the new ones.
This is not a an easy task, but it is doable if you take your time and work methodically. Now is not the time to try shortcuts.
What you need is an ETL (extract, transform, load) tool.
http://en.wikipedia.org/wiki/Extract,_transform,_load#Tools
I don't really know how far an 'ETL' tool will get you depending on the original and new database designs. In my career I've had to do more than a few data migrations and we usually always had to design a special utility which would update a fresh database with records from the old database, and yes we coded it complete with all the update/insert statements that would transform data.
I don't know how many tables your database has, but if they are not too many then you could consider going the grunt root. That's one technique that's guaranteed to work after all.
If you go to your database in SSMS and right-click, under tasks should be an option for "Import Data". You can try to use that. It's basically just a wizard that creates an SSIS package for you, which it can then either run for you automatically or which you can save and then alter as needed.
The big issue is how you need to transform the data. This goes into a lot of specifics which you don't include (and which are probably too numerous for you to include here anyway).
I'm certain that SSIS can handle whatever transformations you need to do to change it from the old format to the new. An alternative though would be to just import the tables into MS SQL as-is into staging tables, then use SQL code to transform the data into the 3NF tables. It's all a matter of what your most comfortable with. If you go the second route, then the import process that I mentioned above in SSMS could be used. It will even create the destination tables for you. Just be sure that you give them unique names, maybe prefixing them with "STG_" or something.
Davud mentioned linked servers. That's definitely another way that you can go (and got my upvote). Personally, I prefer to copy the tables over into MS SQL first since linked servers can sometimes have weirdness, especially when it comes to data types not mapping between different providers. Having the tables all in MS SQL will also probably be a bit faster and saves time if you have to rerun or correct portions of the data. As I said though, the linked server method would probably be fine too.
I have done this going the other direction and SSIS works fine, although I might have needed to use a script task to deal with slight data type weirdness. SSIS does ETL.