0

I want to import a .sql file so that my new schema and datas is the one and the .sql file (so I don't care about losing my current schema and datas)

I tried rails db < sql-file-path but it returns me an error :

enter image description here

I've found this answer but it's not clear what this is really doing, like we have to create a migration to execute ruby code and import a file ? Every solution is welcome :)

2 Answers 2

2

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!

Sign up to request clarification or add additional context in comments.

Comments

0

In this case I would follow these steps:

  1. Backup your database
  2. Run the script
  3. Create Rails models for any new tables you imported
  4. Recreate the schema.rb file from the database

    bundle exec rake db:schema:dump

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.