0

I'm trying to use Python 3.9.9 and subprocess to drive a MySQL import like this:

with open("./dump.sql") as f:
    import_db = subprocess.run([
        "mysql",
        "--user=me",
        "--password=password",
        "--host=127.0.0.1",
        "db_name"
    ], check=True, stdin=f)
    print(import_db)

It is running without error, but the data is not being imported:

mysql: [Warning] Using a password on the command line interface can be insecure.
CompletedProcess(args=['mysql', '--user=me', '--password=password', '--host=127.0.0.1', 'db_name'], returncode=0)

Checking the database after, and db_name is not present. I've tried a few different ways of passing stdin without luck.

Any help is appreciated! Thanks!

Dan
  • 602
  • 9
  • 24
  • instead of opening the file make it like https://stackoverflow.com/questions/17666249/how-do-i-import-an-sql-file-using-the-command-line-in-mysql – nbk Jan 14 '22 at 21:03

0 Answers0