I have dumped a MySQL database (all tables) for use with PHPUnit using this command:
mysqldump --xml -t -u [username] --password=[password] [database] > /path/to/file.xml
I need to modify the test data, so I need to re-import it back into the database so I can work on it with MySQL workbench.
What is the command to reimport it back into a specified database?
And no, it's not as simple as LOAD XML, that works on a table by table basis, but this export has all tables in it.
NO, there is no built in way present to restore a XML formatted dump file. You can check this blog Restoring XML-formatted MySQL dumps for information on this as well as this existing post How to restore a mysql xml database file from mysql command line?
Related
I need to know to how to export all the tables in the database as .sql files using mysqldump. i need to set them into separate files per table for easy restore process.
Please note that there is over 100+ tables in the database that following option is NOT GOING to help me.
mysqldump -p --user=username dbname tableName > tableName.sql
Note:
Also prefer a Single Command rather than set of commands in shell scripts with forloops.
Mysqldump does not have an option to dump a separate .sql file per table.
You can use mysqldump --tab to dump a separate CSV file per table (but keep in mind this dumps the files on the database server, not on the host where you run the command, so it won't work for example if you use RDS).
You can also use mydumper which is an open-source tool. This dumps two .sql files for each table: one with the CREATE TABLE definition, and a second file that contains the data.
I'm trying to create a full backup of multiple databases in MySQL using the --all-databases command but the output sql file is always only 1kb.
When I specify each database individually using just the --databases command the databases are backed up but it does not restore all tables when I upload the dump file to another MySQL installation.
Currently, I am using mysql version 5.0.45 - community-nt. I have created tables in that database. After that, I export the script file from and I imported other mysql server. That version is 5.5.29. In my tables, there is BIT datatype. When I imported my exported data to other mysql version, the imported data are changed. Imported data are not correct. So, How shall I handle.
If you're exporting with the mysqldump command you can use the --compatible option. For some reason there isn't a mysql50 option but you can use mysql40 and it should work for you:
mysqldump -uuser -ppassword -hyour.host \
--compatible=mysql40 your_database > your_database.sql
I am trying to do some maintenance on MySQL database data and I created a dump file with the backed up current database.
I want to restore all that data into another database called something like original_db_name_test
Is there a command for that?
This depends on how you invoked mysqldump
If you used mysqldump dbname, then your dump contains neither CREATE DATABASE nor USE DATABASE.
Just create the database with the new name and feed the dump to mysql -D new_dbname.
If you used mysqldump --database dbname, then the dump contains CREATE DATABASE and USE DATABASE statements.
You need to comment them out or replace with new_dbname.
mysql -u usernamehere -p original_db_name_test < yourdumpfilehere.sql
If you used mysqldump to create the dump file, simply:
Create a new database (use the mysqladmin command line tool - "mysqladmin create [new database name]").
Edit the dump file to add a "USE [new database name];" at the top. (There might be an existing use statement that's commented out, so you can change this and un-comment it.)
Import the dump into the new table via "mysql -u <user name> -p < [dump file name]".
Incidentally, when creating a dump via mysqldump, I'd be tempted to use the "--add-drop-table" option, as this will cull any existing table with the same name prior to issuing the table creation statement.
you can use the 'MySQL Workbench' Application and do this with a nice gui
Is it possible to extract a script from an MySQL database to create a copy of the tables on another MySQL database which is located on a remote server?
You can dump either the structure of the tables, or their content, using the mysqldump command-line tool.
For example, to get a dump of the structure (create table instructions) of all tables of a database, you can use something like this :
mysqldump --no-data --user=USER_NAME --password=PASSWORD --host=HOST DATABASE_NAME
And, to get this to a file, instead of getting it to the standard output, you can redirect that output :
mysqldump --no-data --user=USER_NAME --password=PASSWORD --host=HOST DATABASE_NAME > dump-file.sql
If you also want the data of the tables, and not just their structure, do not use the --no-data option.
Then, on your other server, you can import the dump, using :
mysql --user=NEW_USER_NAME --password=NEW_PASSWORD --host=NEW_HOST NEW_DATABASE_NAME < dump-file.sql
Do you mean to extract a 'dump'?
yes of course. mysqldump utility is the general choice