Commits

lakin.wecker committed 9894d15

adding a MySQL command to create databases.

  • Participants
  • Parent commits 4578c32

Comments (0)

Files changed (1)

File 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):