Questions tagged [mysqldump]

MySQL's Standard Dump/Backup Utility

mysqldump is the client backup program used to dump a database or a collection of databases for backup or transfer to another SQL server.

The output of a mysqldump typically contains SQL statements to create the database schema, only the data, stored procedures, triggers, subsets of data using where clauses, or combinations of them all. Additionally, mysqldump can also be used to generate files in CSV, other delimited text, or XML format.

By default, mysqldump will dump all databases alphabetically, and table alphabetically within each database. If you use your imagination, you can find more creative ways to mysqldump data faster using shell scripting in conjunction with background processes. Also by default, mysqldump uses --opt, which specifies

  • --add-drop-table
  • --add-locks
  • --create-options
  • --disable-keys
  • --extended-insert
  • --lock-tables
  • --quick
  • --set-charset

There are many options that control mysqldump's behavior when dumping MyISAM and InnoDB data, plus accommodations for making the mysqldump's output perform such things as:

  • Binary Log Rotation on the Master prior to dumping
  • Preparing Replication Slaves to change replication coordinates (master Log file,master log position) during reload
  • Adding FLUSH PRIVILEGES; to update user credentials on the server being loaded
  • Make all InnoDB tables dump at the same point-in-time (--single-transaction)

Another feature of mysqldump is the dumping of individual tables in conjunction with a WHERE clause (--where). This allows for dumping portions of a table. If the --where clause involves "EXISTS IN other tables" conditions via JOINs or sub-SELECTs, you must use --lock-all-tables (normally the default, with the exception of dumping an individual table).

745 questions
524
votes
4 answers

How do you mysqldump specific table(s)?

How can I dump a specific table or set of tables without including the rest of the db tables?
markdorison
  • 5,375
  • 3
  • 15
  • 6
285
votes
18 answers

How can I monitor the progress of an import of a large .sql file?

I am importing a 7 GB foobar.sql to restore a table in a local database. $ mysql -h localhost -u root 'my_data' < foobar.sql $ mysql --version /usr/local/mysql/bin/mysql Ver 14.12 Distrib 5.0.96, for apple-darwin9.8.0 (i386) using readline…
qazwsx
  • 3,327
  • 9
  • 21
  • 21
203
votes
7 answers

How can I optimize a mysqldump of a large database?

I have a symfony application with an InnoDB database that is ~2GB with 57 tables. The majority of the size of the database resides in a single table (~1.2GB). I am currently using mysqldump to backup the database nightly. Due to my comcast…
Patrick
  • 4,179
  • 7
  • 27
  • 27
189
votes
4 answers

'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces

I am trying to backup mysql using the command mysqldump -u root -p database_name > backup.sql , but it is throwing an error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump…
subhanshu kumar
163
votes
13 answers

How can I move a database from one server to another?

How can I move MySQL tables from one physical server to another? Such as this exact scenario: I have a MySQL server that uses innodb table and is about 20GB size. I want to move it to a new server, what's the most efficient way to do this?
John
  • 1,791
  • 2
  • 13
  • 10
119
votes
5 answers

MySQL any way to import a huge (32 GB) sql dump faster?

I have this huge 32 GB SQL dump that I need to import into MySQL. I haven't had to import such a huge SQL dump before. I did the usual: mysql -uroot dbname < dbname.sql It is taking too long. There is a table with around 300 million rows, it's…
SBhojani
  • 1,293
  • 2
  • 9
  • 4
106
votes
6 answers

Safest way to perform mysqldump on a live system with active reads and writes?

I'm not sure if this is true but I remember reading if you run the following command in linux mysqldump -u username -p database_name > backup_db.sql while reads and writes are being made to a database then the dump may contain errors. Are there…
user784637
  • 1,195
  • 2
  • 8
  • 7
60
votes
8 answers

Restore mysql database with different name

How can we restore mysql database with different name from mysqldump file. I dont't want to open dump file and edit it. Any other better methods?
Praveen Prasannan
  • 1,466
  • 5
  • 24
  • 38
58
votes
5 answers

Why is DROP DATABASE taking so long? (MySQL)

New CentOS installation. I was running an import of a large DB (2GB sql file) and had a problem. The SSH client seemed to lose the connection and the import seemed to freeze. I used another window to login to mysql and the import appeared to be…
Buttle Butkus
  • 1,220
  • 3
  • 11
  • 21
55
votes
3 answers

Why does InnoDB store all databases in one file?

It was convenient that MyISAM used to store each table in a corresponding file. InnoDB has made advancements in many aspects, but I wonder why InnoDB stores all databases in one file (ibdata1 by default). I understand that InnoDB will map the…
Googlebot
  • 4,377
  • 22
  • 64
  • 87
54
votes
6 answers

How to import a .sql file in MySQL?

I am trying to import a .sql file using MySQL Workbench and I get this error: ERROR 1046 (3D000) at line 28: No database selected I have first created an empty database called with the same name as the .sql file but it doesn't work. I have also…
Barbara Dreamer
48
votes
1 answer

Dump only the Stored Procedures in MySQL

I need to dump only the stored procedures : no data, no table creation. How can I do this using mysqldump?
nakhli
  • 723
  • 2
  • 7
  • 10
46
votes
7 answers

Is it possible to mysqldump a subset of a database required to reproduce a query?

Background I would like to provide the subset of my database required to reproduce a select query. My goal is to make my computational workflow reproducible (as in reproducible research). Question Is there a way that I can incorporate this select…
David LeBauer
  • 3,092
  • 8
  • 29
  • 33
42
votes
4 answers

How do I change the DEFINER of a VIEW in Mysql?

When I run mysqldump, I get an error: mysqldump: Got error: 1449: The user specified as a definer ('root'@'foobar') does not exist when using LOCK TABLES This makes sense because foobar is a legacy machine that no longer exists. How do I change the…
kfmfe04
  • 819
  • 2
  • 8
  • 12
41
votes
8 answers

MySQL DB import/export command line in Windows

How do I import and export a local instance of a MySQL database via command-line interface? My operating system is Windows and WampServer server is installed.
Bharanikumar
  • 519
  • 1
  • 4
  • 5
1
2 3
49 50