Skip to content
Advertisement

Importing .bak MySQL database with Python using pymssql

The title is pretty self explanotory.

I’ve tried the following code :

import _mssql

conn = _mssql.connect(server='', user='', password='', database='')
conn.execute_non_query("IF EXISTS (SELECT 0 FROM sys.databases WHERE name = 'mydb') BEGIN ALTER DATABASE mydb MODIFY NAME = mydb_old END")
conn.execute_non_query("RESTORE DATABASE mydb FROM DISK='C:mydb.bak'")

But I get the following error : No module named ‘_mssql’. I have the version 2.2.2 of pymssql and I use Python 3.9.

I’m just trying to write and read from this database, and I only have the .bak file. I’m quite new to SQL, so I might be doing it the wrong way ? I only have a .bak file though, nothing else.

Thank you for your time.

Advertisement

Answer

As mentioned in the comments:

  • MySQL <> MS SQL

  • And I have to fill the server = “”, user = “”, etc …

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement