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.

1 answer

  • answered 2021-10-13 12:42 FluidMechanics Potential Flows

    As mentioned in the comments:

    • MySQL <> MS SQL

    • And I have to fill the server = "", user = "", etc ...

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum