Database inaccessible when Exporting - mysql

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

Related

Query on mysqldump

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.

export saved MySQL query with database?

I need to export my database, however when I done so and tested it by importing it again in do a different MySQL instance all my bookmarked queries were gone.
How do I export them with the database, so other people can run them by importing the database?
Is there another way?
I could just export each query as a table and have it as separate to the data base
Bookmarked queries have nothing to do with the database. It's a feature of the client. For example that standard linux mysql CLI saves all executed querys to a file name .mysql_history. Like wise whatever client it is that you are using will have a place where this queries are saved, you just need to find it.

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.

if we only have access to phpMyAdmin what's the best way to backup the entire db?

For someone that is not used to mySQL, when using phpMyAdmin administration program, what is the recommended setup to backup the entire database with all tables and with data?
Most of those options are fine, but check the Structure -> "Add DROP TABLE..." and "Add CREATE PROCEDURE", then Data -> "Extended inserts" (this decreases loading time when re-inserting the data and isn't essential). Then click "Save as file" and export, the rest of the options are suitable.
I'm assuming that your database is large and you're having problems with phpMyAdmin timing out. If that's the case, and you don't have shell access, then you may have to write a PHP script, which executes a mysqldump command, and then call it asynchronously so there is no browser timeout issue. It would be a sloppy workaround, but if the access is limited, something like that may be your only option.
Although it has it's places, phpmyadmin's strong suit is not database backups.
Having said that, if your database is small, using the default settings via an .sql export should be fine.
If your database is large (i.e. more than a couple MB) and/or you care about it, backups should be done on the server level via logical copy, or by doing a mysqldump.

Exporting a MySQL database through PHPMyAdmin

I'm hoping to export a database that I only have access to through phpMyAdmin so that I can make a copy of it on my localhost. I've never done this before and the database is fairly large at 200 tables. Does anyone have experience doing this? I'm just unsure if the web interface of phpMyAdmin is a reliable way to export that much data or if I'd be causing some performance issues by attempting to export the data.
Thanks for any advice. Thy phpMyAdmin version is 2.1 if that helps any.
In the table, select Export, tick the "Save as file" option, and keep the selection as "Compression: None".
You will be able to download huge data tables like this.
The issue you will come against is the max_execution_time setting.
What i have found is large databases take longer to dump than what is set here (defaults to 30 seconds).
This will cause your export to fail.
Also make sure you are not trying to dump to the browser, I have found that option unreliable. Choose the save to a file option, and download the dump via ftp .
But as Col. Shrapnel said, try it first!