Path: blob/main/resources/drop_db.py
469 views
#!/usr/bin/env python1# type: ignore2from __future__ import annotations34import os5import sys6import uuid7from optparse import OptionParser89import singlestoredb as s2101112# Handle command-line options13usage = 'usage: %prog [options]'14parser = OptionParser(usage=usage, add_help_option=False)15parser.add_option(16'-h', '--host', default='127.0.0.1',17help='database hostname or IP address',18)19parser.add_option(20'-P', '--port', type='int', default=3306,21help='database port',22)23parser.add_option(24'--password',25help='user password',26)27parser.add_option(28'-u', '--user',29help='username',30)31parser.add_option(32'-d', '--database',33help='database name to use',34)35parser.add_option(36'--help',37help='display usage information',38)3940(options, args) = parser.parse_args()4142if options.help:43parser.print_help()44sys.exit(1)4546database = options.database.strip()47if not database:48print('error: database name must be specified', file=sys.stderr)49sys.exit(1)5051with s2.connect(52f'mysql://{options.host}:{options.port}',53user=options.user, password=options.password,54) as conn:55with conn.cursor() as cur:56cur.execute(f'DROP DATABASE IF EXISTS `{database}`;')575859