-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdmysql-create-database
More file actions
executable file
·31 lines (23 loc) · 923 Bytes
/
Copy pathdmysql-create-database
File metadata and controls
executable file
·31 lines (23 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
import sys
from subprocess import call
import argparse
def runContainer(containerName, databaseName):
''' Runs the command to create the database given using the container given
'''
call("docker run -it --link="+containerName+":mysql --rm mysql sh -c 'exec mysqladmin -h$MYSQL_PORT_3306_TCP_ADDR -P$MYSQL_PORT_3306_TCP_PORT -uroot -p create "+ databaseName +" '", shell=True)
return
def main():
''' Parse the options from the command line and run the function runContainer
'''
parser = argparse.ArgumentParser(
description="Import a .sql file into a database",
prog="dmysql-import-database")
# Create the options
parser.add_argument("container", help="The mysql container to use")
parser.add_argument("database", help="Database to create")
args = parser.parse_args()
runContainer(containerName=args.container, databaseName=args.database)
return
# Execute the main function
main()