0

I have been given a SQL database snapshot in a file sqlfile.sql

I want to access these data, but I do not know how to proceed. I am new to SQL.

I have a Macbook pro with MacOSX Sierra (10.12) and I have installed mysql with Homebrew. The version of mysql is 8.0.16 running mysql works, I can access the mysql prompt line.

I would like to be able to access the data, in python if possible, but if it has to be through the mysql command line, it is fine. Once I can access the tables, I know how to query the data, that is not any problem.

I tried with MySQL Workbench as well, but it does not work either.

Can someone point me towards some guide on how to proceed? I have spend hours trying to find some clue, but I did not succeed.

Thanks a lot!!!

Pere Munar
  • 49
  • 7
  • 1
    You'll likely need to install MySQL and restore the database using the script (.sql) file. A .sql file can be expected to hold sql statements; since you're referring to it as a "snapshot" I would think it is probably a database backup in sql script for (quite common for MySQL), and running the script on a MySQL server will recreate the database. – Uueerdo Jun 06 '19 at 17:53
  • 1
    To do it via command line, see e.g. [How to import an SQL file using the command line in MySQL?](https://stackoverflow.com/q/17666249) – Solarflare Jun 06 '19 at 18:56
  • Thanks a lot for your answers! I just managed to do it within the mysql terminal and now I have access to it. I had to create the connection first, then go within the terminal and actually fill the database with the data from the file.sql – Pere Munar Jun 06 '19 at 21:44

1 Answers1

0

Finally I managed to solve the problem. It was not really complicated, but I had problems finding the right combination of commands.

What I did was, in the command line enter into the mysql prompt. Once here:

mysql> create database mydatabase

Once done, go outside the mysql prompt and in the normal command line execute:

mysql -uroot -p mydatabase < db_snapshot_file.sql

This populates the database called mydatabase. Once done, from Python I could access it. But first, since I had some problem with the authentication, I had to use this answer to solve it.

To access from Python, I used this information which gave me some indications on how to start.

Pere Munar
  • 49
  • 7