How to Import a SQL File into a Rails Database

How can I import a SQL file into a Rails database?

The easiest way:

bundle exec rails db < $SQL_FILE

example:

bundle exec rails db < my_db.sql

Import SQL file into Rails database

You don't need do necessarily with rails. You can use only mysql if you're comfortable with it. You can access mysql console by:

mysql -u user_name -p 

Exchange "user_name" by your user (root for example), then it will ask for your user password.
When you have access to the console, you can select your development database by:

use your_database_name;

and then, to import:

source your_sql_file.sql

You can check your credentials and your database name on your database.yml.

If it doesn't work, please check your sql syntax or try to generate the dump file again.

Good luck, hope this helps!

How to import a BIG SQL file into a rails database?

Is it a proper SQL file (with SQL statements in it) ?

If so, you should be able to do this on the command line:

mysql target-db-name < sql-file-name.sql -uuser -p

Hit return, it'll prompt you for password and you're off

Remember to substitute in proper values for target-db-name, sql-file-name.sql and user

Note: target-db-name should be created beforehand: I don't think it will auto-create

How import from sql file to mysql db in ruby on rails using cloud9?

From the command line, change directory to whatever directory your dump.sql file is located in and then run:

mysql -u username -p c9 < dump.sql


Source: Run .sql file through command line in MySQL

Import dump/sql file into my postgresql database on Linode

You'll need to get the file onto your server or you'll need to use a different command from your terminal.

If you have the file locally, you can restore without sshing in using the psql command:

psql -h <user@ip_address_of_server> -U <database_username> -d <name_of_the_database> -f local/path/to/your/file.sql

Otherwise, the command is:

psql -U <database_username> -d <name_of_the_database> < remote/path/to/your/file.sql

-U sets the db username, -h sets the host, -d sets the name of the database, and -f tells the command you're restoring from a file.



Related Topics



Leave a reply



Submit