Commits

Mikhail Korobov committed 455fc26

mysql: python 2.5 compatibility + restored utf8 defaults for new databases

Comments (0)

Files changed (1)

fab_deploy/mysql.py

 __all__ = ['mysql_execute', 'mysql_install', 'mysql_create_db', 'mysql_create_user', 'mysqldump']
 
 
-MYSQL_CREATE_USER = """CREATE USER '{db_user}'@'localhost' IDENTIFIED BY '{db_password}';"""
+MYSQL_CREATE_USER = """CREATE USER '%(db_user)s'@'localhost' IDENTIFIED BY '%(db_password)s';"""
 
-MYSQL_CREATE_DB = """CREATE DATABASE {db_name};"""
+MYSQL_CREATE_DB = """CREATE DATABASE %(db_name)s DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"""
 
 MYSQL_GRANT_PERMISSIONS = """
-GRANT ALL ON {db_name}.* TO '{db_user}'@'localhost';
+GRANT ALL ON %(db_name)s.* TO '%(db_user}s'@'localhost';
 FLUSH PRIVILEGES;
 """
 
     if db_password is None:
         db_password = env.conf.DB_PASSWORD
 
-    sql = MYSQL_CREATE_USER.format(db_user=db_user, db_password=db_password)
+    sql = MYSQL_CREATE_USER % dict(db_user=db_user, db_password=db_password)
     mysql_execute(sql, 'root')
 
 def mysql_create_db(db_name=None, db_user=None):
     if db_user is None:
         db_user = env.conf.DB_USER
 
-    sql = MYSQL_CREATE_DB.format(db_name=db_name, db_user=db_user)
+    sql = MYSQL_CREATE_DB % dict(db_name=db_name, db_user=db_user)
     mysql_execute(sql, 'root')
 
     if db_user != 'root':
     if db_user is None:
         db_user = env.conf.DB_USER
 
-    sql = MYSQL_GRANT_PERMISSIONS.format(db_name=db_name, db_user=db_user)
+    sql = MYSQL_GRANT_PERMISSIONS % dict(db_name=db_name, db_user=db_user)
     mysql_execute(sql, 'root')
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.