コード例 #1
0
 def create_db(self, conn):
     """ this optional schema will be used by the application """
     if not self.mysql_db:
         log.warn('No default database configured.')
         return
     sql = 'CREATE DATABASE IF NOT EXISTS `{}`;'.format(self.mysql_db)
     self.execute(sql, conn=conn)
コード例 #2
0
ファイル: libmysql.py プロジェクト: autopilotpattern/mysql
 def create_db(self, conn):
     """ this optional schema will be used by the application """
     if not self.mysql_db:
         log.warn('No default database configured.')
         return
     sql = 'CREATE DATABASE IF NOT EXISTS `{}`;'.format(self.mysql_db)
     self.execute(sql, conn=conn)
コード例 #3
0
ファイル: libmysql.py プロジェクト: autopilotpattern/mysql
    def create_default_user(self, conn):
        """ this optional user will be used by the application """
        if not self.mysql_user or not self.mysql_password:
            log.warn('No default user/password configured.')
            return

        # there's some kind of annoying encoding bug in the lib here
        # so we have to format the string rather than passing it as
        # a param. totally safe, I bet.
        self.add('CREATE USER `{}`@`%` IDENTIFIED BY %s;'
                 .format(self.mysql_user), (self.mysql_password,))
        if self.mysql_db:
            self.add('GRANT ALL ON `{}`.* TO `{}`@`%`;'
                     .format(self.mysql_db, self.mysql_user))
        self.add('FLUSH PRIVILEGES;')
        self.execute_many(conn=conn)
コード例 #4
0
ファイル: libmysql.py プロジェクト: autopilotpattern/mysql
 def initialize_db(self):
     """
     post-installation run to set up data directories
     and install mysql.user tables
     """
     self.make_datadir()
     log.info('Initializing database...')
     try:
         subprocess.check_call(['/usr/bin/mysql_install_db',
                                '--user=mysql',
                                '--datadir={}'.format(self.datadir)])
         log.info('Database initialized.')
         return True
     except subprocess.CalledProcessError:
         log.warn('Database was previously initialized.')
         return False
コード例 #5
0
    def create_default_user(self, conn):
        """ this optional user will be used by the application """
        if not self.mysql_user or not self.mysql_password:
            log.warn('No default user/password configured.')
            return

        # there's some kind of annoying encoding bug in the lib here
        # so we have to format the string rather than passing it as
        # a param. totally safe, I bet.
        self.add(
            'CREATE USER `{}`@`%` IDENTIFIED BY %s;'.format(self.mysql_user),
            (self.mysql_password, ))
        if self.mysql_db:
            self.add('GRANT ALL ON `{}`.* TO `{}`@`%`;'.format(
                self.mysql_db, self.mysql_user))
        self.add('FLUSH PRIVILEGES;')
        self.execute_many(conn=conn)
コード例 #6
0
 def initialize_db(self):
     """
     post-installation run to set up data directories
     and install mysql.user tables
     """
     self.make_datadir()
     log.info('Initializing database...')
     try:
         subprocess.check_call([
             '/usr/bin/mysql_install_db', '--user=mysql',
             '--datadir={}'.format(self.datadir)
         ])
         log.info('Database initialized.')
         return True
     except subprocess.CalledProcessError:
         log.warn('Database was previously initialized.')
         return False