Commits

lakin.wecker committed 9894d15

adding a MySQL command to create databases.

Comments (0)

Files changed (1)

baste/__init__.py

                     self.db_user, user="postgres")
             baste_env.sudo("createdb -O %s %s" % (self.db_user, self.db_name), user="postgres")
 
+#-------------------------------------------------------------------------------
+class UbuntuMysqlCreateDbAndUser(object):
+    #---------------------------------------------------------------------------
+    def __init__(self, db_name, db_user, db_password):
+        self.db_name = db_name
+        self.db_user = db_user
+        self.db_password = db_password
+
+    #---------------------------------------------------------------------------
+    def __call__(self):
+        sql = "CREATE DATABASE %(db)s; " + \
+            "GRANT ALL ON %(db)s.* to %(user)s@localhost IDENTIFIED BY '%(pw)s';"
+        sql = sql % {
+                'db': self.db_name,
+                'user': self.db_user,
+                'pw': self.db_password,
+            }
+
+        command = "echo \"%s\" | mysql -p -u root" % (sql,)
+        print command
+        baste_env.run(command)
+
 
 #-------------------------------------------------------------------------------
 def pay_attention_confirm(question, yes=None):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.