I have a single .sql file which is 800MB in size and contains a few of databases including tables and datas.
The problem is, how to restore this kind of dump since there is no CREATE DATABASE syntax in the file?
I try mysql> -u root -p --all-database < c:\data.sql but no joy.
Conducted a backup of the following.
mysqldump -u xxx -p --all-database > c:\data.sql
Or, in the database unit
mysqldump -u xxx -p --databases db_name > c:\data.sql
Recovery in the following code.
mysql -u root -p < c:\data.sql
I know how mysqldump works.
But dont know where to use it?
If I execute this command after starting mysql program then it says error.
I am using ubuntu. So how can I use this utility?
Backup your database this way too..
mysql -u root -p DB_NAME > db_name_backup.sql
If you want to backup all database simply run this
mysql -u root -p > mysql_db_backup.sql
You will learn more about mysql and mysqldump here..
Guide:
mysqldump and mysql
MySQL Database Backup using mysqldump
shell> mysqldump --opt db_name > backup-file.sql
You can read the dump file back into the server like this:
shell> mysql db_name < backup-file.sql
Or like this:
shell> mysql -e "source /path-to-backup/backup-file.sql" db_name
mysqldump is also very useful for populating databases by copying data
from one MySQL server to another:
shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name
It is possible to dump several databases with one command:
shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql
If you want to dump all databases, use the --all-databases option:
shell> mysqldump --all-databases > all_databases.sql
If tables are stored in the InnoDB storage engine, mysqldump provides a
way of making an online backup of these (see command below). This
backup just needs to acquire a global read lock on all tables (using
FLUSH TABLES WITH READ LOCK) at the beginning of the dump. As soon as
this lock has been acquired, the binary log coordinates are read and
lock is released. So if and only if one long updating statement is
running when the FLUSH... is issued, the MySQL server may get stalled
until that long statement finishes, and then the dump becomes
lock-free. So if the MySQL server receives only short (in the sense of
"short execution time") updating statements, even if there are plenty
of them, the initial lock period should not be noticeable.
shell> mysqldump --all-databases --single-transaction > all_databases.sql
For point-in-time recovery (also known as “roll-forward”, when you need
to restore an old backup and replay the changes which happened since
that backup), it is often useful to rotate the binary log (see
Section 8.4, “The Binary Log”) or at least know the binary log
coordinates to which the dump corresponds:
shell> mysqldump --all-databases --master-data=2 > all_databases.sql
or
shell> mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql
The simultaneous use of --master-data and --single-transaction works as
of MySQL 4.1.8. It provides a convenient way to make an online backup
suitable for point-in-time recovery if tables are stored in the InnoDB
storage engine.
For more information on making backups, see Section 6.1, “Database
Backups”.
mysqldump -u MYSQL_USER -h MYSQL_SERVER -pMYSQL_PASS --all-databases > "dbs.sql"
You use it directly on the terminal, just like mysql it self, and pass the parameters directly to it.
mysqldump -u [user] -p[password] [database name] > dumpfilename.sql
yes you can.
see http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html for more information on the tool.
If it's an entire DB, then:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
If it's all DBs, then:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 >
table_backup.sql
You can even go as far as auto-compressing the output using gzip (if your DB is very big):
$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz
If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name >
db_backup.sql
To IMPORT:
ype the following command to import sql data file:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
In this example, import 'data.sql' file into 'blog' database using vivek as username:
$ mysql -u sat -p -h localhost blog < data.sql
If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql
REfer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html
We recently lost some data from our live DB. We restored an older backup as our current live DB, and have been repairing a more recent partially broken DB as a test DB. Both are running on the same server and the plan is the testing DB will replace the live DB as soon as we're happy the fixes are valid.
Is there an easy way to swap the two DBs, e.g. swap their names, so we can just switch which one is used by the website for some last-minute checks? i.e. we want to set the repaired DB as the live one, but be able to flip back without re-building/re-importing a whole exported version.
I don't know if MySQL allows renaming DBs in this way.
To swap two database schemas that are named db1 and db2:
mysqladmin -uroot -pmypassword create swaptemp
mysqldump -uroot -pmypassword --routines db1 | mysql -u root -pmypassword swaptemp
mysqladmin -uroot -pmypassword drop db1
mysqladmin -uroot -pmypassword create db1
mysqldump -uroot -pmypassword --routines db2 | mysql -u root -pmypassword db1
mysqladmin -uroot -pmypassword drop db2
mysqladmin -uroot -pmypassword create db2
mysqldump -uroot -pmypassword --routines swaptemp | mysql -u root -pmypassword db2
mysqladmin -uroot -pmypassword drop swaptemp
Steps:
Copy the lines into Notepad.
Replace all references to "db1", "db2", "mypassword" (+ optionally "root") with your equivalents.
Execute one by one on the command line (entering "y" when prompted).
i want to move mysql database tables which resides in one computer to another computer. how can i create dump file as we created in Oracle ?
i m using exp command but not working.
Use mysqldump.
mysqldump -u <username> -p<password> <db_name> > <filename>.sql
To import, create empty database named <db_name>, thena -
mysql -u <username> -p<password> <db_name> < <filename>.sql
To export all databases -
mysqldump -u <username> -p<password> --all-databases > <filename>.sql
mysqldump -u <username> -p<password> -h <hostname> <dbname> <tablename> > filename.sql
Now you may need to take the dump of just the schema. For example you use a command called like.
mysql> show create table tablename;
this will give you the query that created the table. Now for some reason you need to take schema dump of all the tables inside you database/databases you may use -d option like this
mysqldump -d -u <username> -p<password> -h <hostname> <dbname> > filename.sql
The -d option means "without data".
Now you have full dump without the data and just the schema.
I had successfully imported a database using command line, but now my pain area is how to import a single table with its data to the existing database using command line.
Linux :
In command line
mysql -u username -p databasename < path/example.sql
put your table in example.sql
Import / Export for single table:
Export table schema
mysqldump -u username -p databasename tableName > path/example.sql
This will create a file named example.sql at the path mentioned and write the create table sql command to create table tableName.
Import a single table into database
mysql -u username -p databasename < path/example.sql
This command needs an sql file containing data in form of insert statements for table tableName. All the insert statements will be executed and the data will be loaded.
Export:
mysqldump --user=root databasename > whole.database.sql
mysqldump --user=root databasename onlySingleTableName > single.table.sql
Import:
Whole database:
mysql --user=root wholedatabase < whole.database.sql
Single table:
mysql --user=root databasename < single.table.sql
Importing the Single Table
To import a single table into an existing database you would use the following command:
mysql -u username -p -D database_name < tableName.sql
Note:It is better to use full path of the sql file tableName.sql
First of all, login to your database and check whether the database table which you want to import is not available on your database.
If it is available, delete the table using the command. Else it will throw an error while importing the table.
DROP TABLE Table_Name;
Then, move to the folder in which you have the .sql file to import and run the following command from your terminal
mysql -u username -p databasename < yourtable.sql
The terminal will ask you to enter the password. Enter it and check the database.
Command Line
Import / Export for single table:
Exporting table schema
-> mysqldump -u your_user_name -p your_database_name table_name > test.sql
This will create a file named test.sql and creates table sql command to create table table_name.
Importing data into table
-> mysql -u your_user_name -p database_name table_name < test.sql
Make sure your test.sql file is in the same directory, if not navigate through the path and then run the command.
It works correctly...
C:\>mysql>bin>mysql -u USERNAME DB_NAME < tableNameFile.sql
please note .sql file specified your current database..
We can import single table using CMD as below:
D:\wamp\bin\mysql\mysql5.5.24\bin>mysql -h hostname -u username -p passowrd databasename < filepath
If you're in the pwd of an SQL dump and you need a table from that, do this:
sed -n '/-- Table structure for table `'TableNameTo_GrabHere'`/,/-- Table/{ /^--.*$/d;p }' dump_file_to_extract_from.sql > table_name_here.sql
Then just import the table you extracted from the above into the needed database
you can do it in mysql command instead of linux command.
1.login your mysql.
2.excute this in mysql command:
use DATABASE_NAME;
SET autocommit=0 ; source ABSOLUTE_PATH/TABLE_SQL_FILE.sql ; COMMIT ;
if you already have the desired table on your database, first delete it and then run the command below:
mysql -u username -p databasename < yourtable.sql
From server to local(Exporting)
mysqldump -u username -p db_name table_name > path/filename.sql;
mysqldump -u root -p remotelab welcome_ulink >
/home_local/ladmin/kakalwar/base/welcome_ulink.sql;
From local to server(Importing)
mysql -u username -p -D databasename < path/x/y/z/welcome_queue.sql
mysql -u root -p -D remotelab <
/home_local/ladmin/kakalwar/instant_status/db_04_12/welcome_queue.sql
Also its working. In command form
cd C:\wamp\bin\mysql\mysql5.5.8\bin //hit enter
mysql -u -p databasename //-u=root,-p=blank
It would be combination of EXPORT INTO OUTFILE and LOAD DATA INFILE
You need to export that single table with EXPORT INTO OUTFILE, this will export table data to a file. You can import that particular table using LOAD DATA INFILE
Refer doc1 , doc2
To import a particular table in database follow below command.
Here table_name.sql is dump of taht particular table that you are going to import
mysql -u root -p database_name table_name < table_name.sql
To export a particular table from database follow below command.
mysqldump -u root -p database_name table_name > table_name.sql
-> mysql -h host -u user -p database_name table_name < test_table.sql
Using a temporary database could be a solution depending on the size of the database.
mysql -u [username] -p -e "create database tempdb"
mysql -u [username] -p tempdb < db.sql
mysqldump -u [username] -p tempdb _table_to_import_ > table_to_import.sql
mysql -u [username] -p maindb < table_to_import.sql
To import a table into database, if table is already exist then add this line in your sql file DROP TABLE IF EXIST 'table_name' and run command mysql -u username -p database_name < import_sql_file.sql.
Please verify the sql file path before execute the command.
Open the backup file in the VScode and search the table name copy the create table and insert command for the table. Copy and execute those two commands in the database where it is required.
Use the below command to import a single table into the database on RDS
mysql -h rds_end_point -u username -p databasename < example.sql
First of all take backup of your both database, step 2 select table which you want to export now select export button now download sql file now you have to import into another database simply select database and then import sql file ... simple and easy.