Commits

Mikhail Korobov committed 43d6cfd

mysql_create_db asks for root mysql password if it is not found in env

  • Participants
  • Parent commits 08a3dff

Comments (0)

Files changed (2)

File docs/guide.rst

    empty database named ``env.conf['INSTANCE_NAME']`` (it equals to
    ``env.user`` by default).
 
+   .. note::
+
+        If non-root mysql user is used then you'd better create DB and
+        grant necessary priveleges manually.
+
 
 3. If you feel brave you can now run ``fab full_deploy`` from the project root
    and get a working django site.

File fab_deploy/mysql.py

     password = env.conf['DB_PASSWORD']
     run('mysqldump -uroot -p%s %s > %s/%s%s.sql' % (password, db, dir, db, now))
 
-def mysql_execute(sql):
-    run ("echo '%s' | mysql -u%s -p%s" % (sql, env.conf['DB_USER'], env.conf['DB_PASSWORD']))
+def mysql_execute(sql, user=None, password=None):
+    user = user or env.conf['DB_USER']
+    password = env.conf['DB_PASSWORD'] if password is None else password
+    run ("echo '%s' | mysql -u%s -p%s" % (sql, user , password))
 
 def mysql_create_db():
     db_name = env.conf['DB_NAME']
+    if env.conf['DB_USER'] != 'root':
+        password = prompt('Please enter mysql root password:')
+    else:
+        password = env.conf['DB_PASSWORD']
     params = 'DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci'
-    mysql_execute('CREATE DATABASE %s %s;' % (db_name, params))
+    mysql_execute('CREATE DATABASE %s %s;' % (db_name, params), 'root', password)