Query on mysqldump - mysql

I am trying to use mysqldump for backing up my database and restoring the same in remote a machine for disaster recovery purposes. As I havent used it before, I am having a basic question regarding the same.
Once I dumped and copied over the file,on the target machine, while importing, will it perform the import such a way that it creates new entities while updating any existing ones and deleting any entities deleted in the dump?
Basically, will it keep the target mysql in sync with the dump i.e. the same as on the source?
Thanks

Long story short(ish):
Mysqldump will create an SQL file that, when imported in an empty environment, makes a database that is the same as the one the dump was created from.
So no: it will not "sync" anything (e.g. delete files or update records). You can actually look at the file and you will see statements that first create a database, then create the tables and finally insert your data.
They way it works that you take an empty server, import the database and you have you origional situation back. Nothing less, but definitely nothing more as well.

Related

recovering a mysql database using a copy of the datafiles

The primary HDD drive of my computer died yesterday, I got a new one and restored it but when I went to restore my mysql databases I realize I had no done a proper backup in a while.
Nevertheless, I do have the original database files from my previous installation as the datafiles were in the second HDD.
My question is, can I restore/create a new DB in the new machine using only the files from the previous installation?
Thank,
Ignacio
Yes, you should be able to do this.
I'm a bit unclear: when you say, "I do have the original database files" do you mean as a database? If so, go to phpMySql for the surviving database and choose Export. Export the database as a text file. Open the file with your favorite text editor and change the name of the database to match the name you are importing into.
Create the empty database where you want the new one to be, if it doesn't already exist. Now go to phpMySql for that database and import your text file. This should recreate all the tables and their data in the new location.
If instead, you only have the files that were the source of the data, then you need to use whatever tool was used to create the database in the first place. For example, if the data is in the form on an Excel spreadsheet, you would use MySql for Excel.
Hope this helps!
(after your comment that you have file backups of WordPress site)
In that case, you may not be so lucky. If you used a tool to do your backup, it may have backed up the database, but in general, the database is stored separately from your file system. So if you just copied the files yourself, you won't have the database. But do look for any file with a suffix of .SQL, which would be a database backup.
Next, contact your Internet Service Provider and see if they do periodic database backups. If so, you can recover from them.
For the future, see if your ISP provides automated backups (including database). And read https://codex.wordpress.org/WordPress_Backups.

Database inaccessible when Exporting

I am exporting a MySQL database that is currently in use by an application, but when I start the process the database becomes inaccessible and the application does not work, so I had to terminate the export process to allow the application to use it again. As the application is live, I cant let it go offline. Is this a normal thing, that MySQL database doesn't work when being exported, or do I need to do something in particular to export it this way?
Are you using mysqldump? Sounds like your tables are being locked.
Are you working with InnoDB tables? If you are using mysqldump, I'd look into the --single-transaction option. That will take a snapshot, but the key thing to remember is that any data changed during the export will not be reflected in the output. It will be in the production db, just not in the export until next time.
https://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_single-transaction

Exported MySQL database without procedures by mistake

I've exported a database via SSH and I didn't add --routine command to export the routines.
Now I don't have any access to this database, and I have only one .sql file. is there any way to restore and find the routines through PHP code or database structures?
No, sorry, in this case I think you're out of luck. Looking at the database structure, you won't be able to figure out what a routine might have done. Likewise, looking at the PHP code is probably not going to help. If you know what the routines did (for instance, manipulate data on insert, maintenance by deleting some rows, or some such) you can work through recreating it, but that's basically reverse engineering it based on what breaks when you try to run your application.

Export Specific Records from MySql Workbench

I have databases in my system and also put database on web server also, so when I update my system database data I ll have to then replace or add data into web database.
but
problem is that I am doing changes in database to some specific record frequently for testing purpose.
So I want some mechanism that will used to export some specific records to sql file with insert statement.
Suppose I have made change in table tbl1 and added 10 records to it.
So right now I am manually adding or replacing whole table on web database.
So is there any mechanism in MySql or in Workbench using that I can export specific records.
Any Help for that.
The only automatic solution is to use replication, but that is probably not a good solution for your scenario. So what remains is some manual process. Here are some ideas:
Write a script that writes specific records into a dump file.
Then use a different script to load this dump file into your
target server.
If you frequently change the same records you could create a script
with insert statements that you edit for each new value and run
against both your local and your remote (web) server.

Import MySQL DAtabase from Data Files

I've got the MySQL data files from an old server which has now crashed so I can not login to the server to do mysqldump etc. I am now trying to load the data on a new server. The only option I have is to copy/paste the data files that I have. But when I do so, some of the database tables throw this error "Table does not exist" when I can see it in my Navicat Window. The problem is only with some of the tables, not all.
My question is, how can I fix this error ? Or is there another way to import the data from data files?
The best piece of advice that comes to my mind is running a myisamchk on the respective table(s), paying special attention to the repair options.
Be sure to make backups of the data files beforehand.
Additional thoughts:
Make sure you have restarted the database server after adding the data files.
Are you sure you are addressing the correct table(s)? Note that on most Linux filesystems, the table name is case sensitive (as it's reflected by a file in the filesystem). So tablename != Tablename