Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
singlestore-labs
GitHub Repository: singlestore-labs/singlestoredb-python
Path: blob/main/resources/drop_db.py
469 views
1
#!/usr/bin/env python
2
# type: ignore
3
from __future__ import annotations
4
5
import os
6
import sys
7
import uuid
8
from optparse import OptionParser
9
10
import singlestoredb as s2
11
12
13
# Handle command-line options
14
usage = 'usage: %prog [options]'
15
parser = OptionParser(usage=usage, add_help_option=False)
16
parser.add_option(
17
'-h', '--host', default='127.0.0.1',
18
help='database hostname or IP address',
19
)
20
parser.add_option(
21
'-P', '--port', type='int', default=3306,
22
help='database port',
23
)
24
parser.add_option(
25
'--password',
26
help='user password',
27
)
28
parser.add_option(
29
'-u', '--user',
30
help='username',
31
)
32
parser.add_option(
33
'-d', '--database',
34
help='database name to use',
35
)
36
parser.add_option(
37
'--help',
38
help='display usage information',
39
)
40
41
(options, args) = parser.parse_args()
42
43
if options.help:
44
parser.print_help()
45
sys.exit(1)
46
47
database = options.database.strip()
48
if not database:
49
print('error: database name must be specified', file=sys.stderr)
50
sys.exit(1)
51
52
with s2.connect(
53
f'mysql://{options.host}:{options.port}',
54
user=options.user, password=options.password,
55
) as conn:
56
with conn.cursor() as cur:
57
cur.execute(f'DROP DATABASE IF EXISTS `{database}`;')
58
59