We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add new method to return the columns for MySQL datasources :electric_plug: :1234: 
When MindsDB creates a new MySQL datasource we get information for columns by fetching all datasources. The problem here is that if datasource is big it takes a lot of time. We need a new get_columns method to return the columns name per datasource. The PR should include this method inside the MySQL class .

## Steps :male_detective: :female_detective: 

- Implement in https://github.com/mindsdb/mindsdb/blob/stable/mindsdb/integrations/mysql/mysql.py#L51
- Push to staging branch

## Additional rewards :1st_place_medal: 

Each code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/
 



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mindsdb/integrations/mysql/mysql.py`
Content:
```
1 import os
2 import shutil
3 import tempfile
4 
5 from contextlib import closing
6 import mysql.connector
7 
8 from lightwood.api import dtype
9 from mindsdb.integrations.base import Integration
10 from mindsdb.utilities.log import log
11 
12 
13 class MySQLConnectionChecker:
14     def __init__(self, **kwargs):
15         self.host = kwargs.get('host')
16         self.port = kwargs.get('port')
17         self.user = kwargs.get('user')
18         self.password = kwargs.get('password')
19         self.ssl = kwargs.get('ssl')
20         self.ssl_ca = kwargs.get('ssl_ca')
21         self.ssl_cert = kwargs.get('ssl_cert')
22         self.ssl_key = kwargs.get('ssl_key')
23 
24     def _get_connnection(self):
25         config = {
26             "host": self.host,
27             "port": self.port,
28             "user": self.user,
29             "password": self.password
30         }
31         if self.ssl is True:
32             config['client_flags'] = [mysql.connector.constants.ClientFlag.SSL]
33             if self.ssl_ca is not None:
34                 config["ssl_ca"] = self.ssl_ca
35             if self.ssl_cert is not None:
36                 config["ssl_cert"] = self.ssl_cert
37             if self.ssl_key is not None:
38                 config["ssl_key"] = self.ssl_key
39         return mysql.connector.connect(**config)
40 
41     def check_connection(self):
42         try:
43             con = self._get_connnection()
44             with closing(con) as con:
45                 connected = con.is_connected()
46         except Exception:
47             connected = False
48         return connected
49 
50 
51 class MySQL(Integration, MySQLConnectionChecker):
52     def __init__(self, config, name, db_info):
53         super().__init__(config, name)
54         self.user = db_info.get('user')
55         self.password = db_info.get('password')
56         self.host = db_info.get('host')
57         self.port = db_info.get('port')
58         self.ssl = db_info.get('ssl')
59         self.ssl_ca = db_info.get('ssl_ca')
60         self.ssl_cert = db_info.get('ssl_cert')
61         self.ssl_key = db_info.get('ssl_key')
62 
63     def _to_mysql_table(self, dtype_dict, predicted_cols, columns):
64         subtype_map = {
65             dtype.integer: 'int',
66             dtype.float: 'double',
67             dtype.binary: 'bool',
68             dtype.date: 'Date',
69             dtype.datetime: 'Datetime',
70             dtype.binary: 'VARCHAR(500)',
71             dtype.categorical: 'VARCHAR(500)',
72             dtype.tags: 'VARCHAR(500)',
73             dtype.image: 'VARCHAR(500)',
74             dtype.video: 'VARCHAR(500)',
75             dtype.audio: 'VARCHAR(500)',
76             dtype.short_text: 'VARCHAR(500)',
77             dtype.rich_text: 'VARCHAR(500)',
78             dtype.array: 'VARCHAR(500)'
79         }
80 
81         column_declaration = []
82         for name in columns:
83             try:
84                 col_subtype = dtype_dict[name]
85                 new_type = subtype_map[col_subtype]
86                 column_declaration.append(f' `{name}` {new_type} ')
87                 if name in predicted_cols:
88                     column_declaration.append(f' `{name}_original` {new_type} ')
89             except Exception as e:
90                 log.error(f'Error: can not determine mysql data type for column {name}: {e}')
91 
92         return column_declaration
93 
94     def _escape_table_name(self, name):
95         return '`' + name.replace('`', '``') + '`'
96 
97     def _query(self, query):
98         con = self._get_connnection()
99         with closing(con) as con:
100             cur = con.cursor(dictionary=True, buffered=True)
101             cur.execute(query)
102             res = True
103             try:
104                 res = cur.fetchall()
105             except Exception:
106                 pass
107             con.commit()
108 
109         return res
110 
111     def _get_connect_string(self, table):
112         user = f"{self.config['api']['mysql']['user']}_{self.name}"
113         password = self.config['api']['mysql']['password']
114         host = self.config['api']['mysql']['host']
115         port = self.config['api']['mysql']['port']
116 
117         if password is None or password == '':
118             connect = f'mysql://{user}@{host}:{port}/mindsdb/{table}'
119         else:
120             connect = f'mysql://{user}:{password}@{host}:{port}/mindsdb/{table}'
121 
122         return connect
123 
124     def setup(self):
125         self._query(f'DROP DATABASE IF EXISTS {self.mindsdb_database}')
126         self._query(f'CREATE DATABASE IF NOT EXISTS {self.mindsdb_database}')
127 
128         connect = self._get_connect_string('predictors')
129 
130         q = f"""
131             CREATE TABLE IF NOT EXISTS {self.mindsdb_database}.predictors (
132                 name VARCHAR(500),
133                 status VARCHAR(500),
134                 accuracy VARCHAR(500),
135                 predict VARCHAR(500),
136                 select_data_query VARCHAR(500),
137                 external_datasource VARCHAR(500),
138                 training_options VARCHAR(500),
139                 key name_key (name)
140             ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';
141         """
142         self._query(q)
143 
144         connect = self._get_connect_string('commands')
145 
146         q = f"""
147             CREATE TABLE IF NOT EXISTS {self.mindsdb_database}.commands (
148                 command VARCHAR(500),
149                 key command_key (command)
150             ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';
151         """
152         self._query(q)
153 
154     def register_predictors(self, model_data_arr):
155         for model_meta in model_data_arr:
156             name = model_meta['name']
157             predict = model_meta['predict']
158             if not isinstance(predict, list):
159                 predict = [predict]
160             columns_sql = ','.join(self._to_mysql_table(
161                 model_meta['dtype_dict'],
162                 predict,
163                 list(model_meta['dtype_dict'].keys())
164             ))
165             columns_sql += ',`when_data` varchar(500)'
166             columns_sql += ',`select_data_query` varchar(500)'
167             columns_sql += ',`external_datasource` varchar(500)'
168             for col in predict:
169                 columns_sql += f',`{col}_confidence` double'
170                 if model_meta['dtype_dict'][col] in (dtype.integer, dtype.float):
171                     columns_sql += f',`{col}_min` double'
172                     columns_sql += f',`{col}_max` double'
173                 columns_sql += f',`{col}_explain` varchar(500)'
174 
175             connect = self._get_connect_string(name)
176 
177             self.unregister_predictor(name)
178             q = f"""
179                 CREATE TABLE {self.mindsdb_database}.{self._escape_table_name(name)} (
180                     {columns_sql},
181                     index when_data_index (when_data),
182                     index select_data_query_index (select_data_query),
183                     index external_datasource_index (external_datasource)
184                 ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';
185             """
186             self._query(q)
187 
188     def unregister_predictor(self, name):
189         q = f"""
190             drop table if exists {self.mindsdb_database}.{self._escape_table_name(name)};
191         """
192         self._query(q)
193 
194     def get_row_count(self, query):
195         q = f""" 
196             SELECT COUNT(*) as count
197             FROM ({query}) as query;"""
198         result = self._query(q)
199         return result[0]['count']
200 
201     def get_columns(self):
202         q = f"""SELECT COLUMN_NAME ,TABLE_NAME
203                     FROM INFORMATION_SCHEMA.COLUMNS 
204                     WHERE TABLE_SCHEMA = database()
205                     ORDER BY COLUMN_NAME, TABLE_NAME;"""
206         columns_list = self._query(q)
207         columns = [f"{columns[0]}.{columns[1]}" for columns in columns_list]
208         return columns
209     
210     def get_tables_list(self):
211         q= f"""
212             SHOW TABLES;
213             """
214         result = self._query(q)
215         return result
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mindsdb/integrations/mysql/mysql.py b/mindsdb/integrations/mysql/mysql.py
--- a/mindsdb/integrations/mysql/mysql.py
+++ b/mindsdb/integrations/mysql/mysql.py
@@ -198,18 +198,18 @@
         result = self._query(q)
         return result[0]['count']
 
-    def get_columns(self):
-        q = f"""SELECT COLUMN_NAME ,TABLE_NAME
-                    FROM INFORMATION_SCHEMA.COLUMNS 
-                    WHERE TABLE_SCHEMA = database()
-                    ORDER BY COLUMN_NAME, TABLE_NAME;"""
-        columns_list = self._query(q)
-        columns = [f"{columns[0]}.{columns[1]}" for columns in columns_list]
-        return columns
+    def get_columns(self,query):
+        q = f"""SELECT * from ({query}) LIMIT 1;"""
+        query_response = self._query(q)
+        if len(query_response) > 0:
+            columns = list(query_response[0].keys())
+            return columns
+        else:
+            return []
     
     def get_tables_list(self):
         q= f"""
             SHOW TABLES;
             """
         result = self._query(q)
-        return result
\ No newline at end of file
+        return result

{"golden_diff": "diff --git a/mindsdb/integrations/mysql/mysql.py b/mindsdb/integrations/mysql/mysql.py\n--- a/mindsdb/integrations/mysql/mysql.py\n+++ b/mindsdb/integrations/mysql/mysql.py\n@@ -198,18 +198,18 @@\n         result = self._query(q)\n         return result[0]['count']\n \n-    def get_columns(self):\n-        q = f\"\"\"SELECT COLUMN_NAME ,TABLE_NAME\n-                    FROM INFORMATION_SCHEMA.COLUMNS \n-                    WHERE TABLE_SCHEMA = database()\n-                    ORDER BY COLUMN_NAME, TABLE_NAME;\"\"\"\n-        columns_list = self._query(q)\n-        columns = [f\"{columns[0]}.{columns[1]}\" for columns in columns_list]\n-        return columns\n+    def get_columns(self,query):\n+        q = f\"\"\"SELECT * from ({query}) LIMIT 1;\"\"\"\n+        query_response = self._query(q)\n+        if len(query_response) > 0:\n+            columns = list(query_response[0].keys())\n+            return columns\n+        else:\n+            return []\n     \n     def get_tables_list(self):\n         q= f\"\"\"\n             SHOW TABLES;\n             \"\"\"\n         result = self._query(q)\n-        return result\n\\ No newline at end of file\n+        return result\n", "issue": "Add new method to return the columns for MySQL datasources :electric_plug: :1234: \nWhen MindsDB creates a new MySQL datasource we get information for columns by fetching all datasources. The problem here is that if datasource is big it takes a lot of time. We need a new get_columns method to return the columns name per datasource. The PR should include this method inside the MySQL class .\r\n\r\n## Steps :male_detective: :female_detective: \r\n\r\n- Implement in https://github.com/mindsdb/mindsdb/blob/stable/mindsdb/integrations/mysql/mysql.py#L51\r\n- Push to staging branch\r\n\r\n## Additional rewards :1st_place_medal: \r\n\r\nEach code PR brings  :three:  point for entry into the draw for a :computer:  Deep Learning Laptop powered by the NVIDIA RTX 3080 Max-Q GPU or other swag :shirt: :bear: .  For more info check out https://mindsdb.com/hacktoberfest/\r\n \r\n\r\n\n", "before_files": [{"content": "import os\nimport shutil\nimport tempfile\n\nfrom contextlib import closing\nimport mysql.connector\n\nfrom lightwood.api import dtype\nfrom mindsdb.integrations.base import Integration\nfrom mindsdb.utilities.log import log\n\n\nclass MySQLConnectionChecker:\n    def __init__(self, **kwargs):\n        self.host = kwargs.get('host')\n        self.port = kwargs.get('port')\n        self.user = kwargs.get('user')\n        self.password = kwargs.get('password')\n        self.ssl = kwargs.get('ssl')\n        self.ssl_ca = kwargs.get('ssl_ca')\n        self.ssl_cert = kwargs.get('ssl_cert')\n        self.ssl_key = kwargs.get('ssl_key')\n\n    def _get_connnection(self):\n        config = {\n            \"host\": self.host,\n            \"port\": self.port,\n            \"user\": self.user,\n            \"password\": self.password\n        }\n        if self.ssl is True:\n            config['client_flags'] = [mysql.connector.constants.ClientFlag.SSL]\n            if self.ssl_ca is not None:\n                config[\"ssl_ca\"] = self.ssl_ca\n            if self.ssl_cert is not None:\n                config[\"ssl_cert\"] = self.ssl_cert\n            if self.ssl_key is not None:\n                config[\"ssl_key\"] = self.ssl_key\n        return mysql.connector.connect(**config)\n\n    def check_connection(self):\n        try:\n            con = self._get_connnection()\n            with closing(con) as con:\n                connected = con.is_connected()\n        except Exception:\n            connected = False\n        return connected\n\n\nclass MySQL(Integration, MySQLConnectionChecker):\n    def __init__(self, config, name, db_info):\n        super().__init__(config, name)\n        self.user = db_info.get('user')\n        self.password = db_info.get('password')\n        self.host = db_info.get('host')\n        self.port = db_info.get('port')\n        self.ssl = db_info.get('ssl')\n        self.ssl_ca = db_info.get('ssl_ca')\n        self.ssl_cert = db_info.get('ssl_cert')\n        self.ssl_key = db_info.get('ssl_key')\n\n    def _to_mysql_table(self, dtype_dict, predicted_cols, columns):\n        subtype_map = {\n            dtype.integer: 'int',\n            dtype.float: 'double',\n            dtype.binary: 'bool',\n            dtype.date: 'Date',\n            dtype.datetime: 'Datetime',\n            dtype.binary: 'VARCHAR(500)',\n            dtype.categorical: 'VARCHAR(500)',\n            dtype.tags: 'VARCHAR(500)',\n            dtype.image: 'VARCHAR(500)',\n            dtype.video: 'VARCHAR(500)',\n            dtype.audio: 'VARCHAR(500)',\n            dtype.short_text: 'VARCHAR(500)',\n            dtype.rich_text: 'VARCHAR(500)',\n            dtype.array: 'VARCHAR(500)'\n        }\n\n        column_declaration = []\n        for name in columns:\n            try:\n                col_subtype = dtype_dict[name]\n                new_type = subtype_map[col_subtype]\n                column_declaration.append(f' `{name}` {new_type} ')\n                if name in predicted_cols:\n                    column_declaration.append(f' `{name}_original` {new_type} ')\n            except Exception as e:\n                log.error(f'Error: can not determine mysql data type for column {name}: {e}')\n\n        return column_declaration\n\n    def _escape_table_name(self, name):\n        return '`' + name.replace('`', '``') + '`'\n\n    def _query(self, query):\n        con = self._get_connnection()\n        with closing(con) as con:\n            cur = con.cursor(dictionary=True, buffered=True)\n            cur.execute(query)\n            res = True\n            try:\n                res = cur.fetchall()\n            except Exception:\n                pass\n            con.commit()\n\n        return res\n\n    def _get_connect_string(self, table):\n        user = f\"{self.config['api']['mysql']['user']}_{self.name}\"\n        password = self.config['api']['mysql']['password']\n        host = self.config['api']['mysql']['host']\n        port = self.config['api']['mysql']['port']\n\n        if password is None or password == '':\n            connect = f'mysql://{user}@{host}:{port}/mindsdb/{table}'\n        else:\n            connect = f'mysql://{user}:{password}@{host}:{port}/mindsdb/{table}'\n\n        return connect\n\n    def setup(self):\n        self._query(f'DROP DATABASE IF EXISTS {self.mindsdb_database}')\n        self._query(f'CREATE DATABASE IF NOT EXISTS {self.mindsdb_database}')\n\n        connect = self._get_connect_string('predictors')\n\n        q = f\"\"\"\n            CREATE TABLE IF NOT EXISTS {self.mindsdb_database}.predictors (\n                name VARCHAR(500),\n                status VARCHAR(500),\n                accuracy VARCHAR(500),\n                predict VARCHAR(500),\n                select_data_query VARCHAR(500),\n                external_datasource VARCHAR(500),\n                training_options VARCHAR(500),\n                key name_key (name)\n            ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';\n        \"\"\"\n        self._query(q)\n\n        connect = self._get_connect_string('commands')\n\n        q = f\"\"\"\n            CREATE TABLE IF NOT EXISTS {self.mindsdb_database}.commands (\n                command VARCHAR(500),\n                key command_key (command)\n            ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';\n        \"\"\"\n        self._query(q)\n\n    def register_predictors(self, model_data_arr):\n        for model_meta in model_data_arr:\n            name = model_meta['name']\n            predict = model_meta['predict']\n            if not isinstance(predict, list):\n                predict = [predict]\n            columns_sql = ','.join(self._to_mysql_table(\n                model_meta['dtype_dict'],\n                predict,\n                list(model_meta['dtype_dict'].keys())\n            ))\n            columns_sql += ',`when_data` varchar(500)'\n            columns_sql += ',`select_data_query` varchar(500)'\n            columns_sql += ',`external_datasource` varchar(500)'\n            for col in predict:\n                columns_sql += f',`{col}_confidence` double'\n                if model_meta['dtype_dict'][col] in (dtype.integer, dtype.float):\n                    columns_sql += f',`{col}_min` double'\n                    columns_sql += f',`{col}_max` double'\n                columns_sql += f',`{col}_explain` varchar(500)'\n\n            connect = self._get_connect_string(name)\n\n            self.unregister_predictor(name)\n            q = f\"\"\"\n                CREATE TABLE {self.mindsdb_database}.{self._escape_table_name(name)} (\n                    {columns_sql},\n                    index when_data_index (when_data),\n                    index select_data_query_index (select_data_query),\n                    index external_datasource_index (external_datasource)\n                ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';\n            \"\"\"\n            self._query(q)\n\n    def unregister_predictor(self, name):\n        q = f\"\"\"\n            drop table if exists {self.mindsdb_database}.{self._escape_table_name(name)};\n        \"\"\"\n        self._query(q)\n\n    def get_row_count(self, query):\n        q = f\"\"\" \n            SELECT COUNT(*) as count\n            FROM ({query}) as query;\"\"\"\n        result = self._query(q)\n        return result[0]['count']\n\n    def get_columns(self):\n        q = f\"\"\"SELECT COLUMN_NAME ,TABLE_NAME\n                    FROM INFORMATION_SCHEMA.COLUMNS \n                    WHERE TABLE_SCHEMA = database()\n                    ORDER BY COLUMN_NAME, TABLE_NAME;\"\"\"\n        columns_list = self._query(q)\n        columns = [f\"{columns[0]}.{columns[1]}\" for columns in columns_list]\n        return columns\n    \n    def get_tables_list(self):\n        q= f\"\"\"\n            SHOW TABLES;\n            \"\"\"\n        result = self._query(q)\n        return result", "path": "mindsdb/integrations/mysql/mysql.py"}], "after_files": [{"content": "import os\nimport shutil\nimport tempfile\n\nfrom contextlib import closing\nimport mysql.connector\n\nfrom lightwood.api import dtype\nfrom mindsdb.integrations.base import Integration\nfrom mindsdb.utilities.log import log\n\n\nclass MySQLConnectionChecker:\n    def __init__(self, **kwargs):\n        self.host = kwargs.get('host')\n        self.port = kwargs.get('port')\n        self.user = kwargs.get('user')\n        self.password = kwargs.get('password')\n        self.ssl = kwargs.get('ssl')\n        self.ssl_ca = kwargs.get('ssl_ca')\n        self.ssl_cert = kwargs.get('ssl_cert')\n        self.ssl_key = kwargs.get('ssl_key')\n\n    def _get_connnection(self):\n        config = {\n            \"host\": self.host,\n            \"port\": self.port,\n            \"user\": self.user,\n            \"password\": self.password\n        }\n        if self.ssl is True:\n            config['client_flags'] = [mysql.connector.constants.ClientFlag.SSL]\n            if self.ssl_ca is not None:\n                config[\"ssl_ca\"] = self.ssl_ca\n            if self.ssl_cert is not None:\n                config[\"ssl_cert\"] = self.ssl_cert\n            if self.ssl_key is not None:\n                config[\"ssl_key\"] = self.ssl_key\n        return mysql.connector.connect(**config)\n\n    def check_connection(self):\n        try:\n            con = self._get_connnection()\n            with closing(con) as con:\n                connected = con.is_connected()\n        except Exception:\n            connected = False\n        return connected\n\n\nclass MySQL(Integration, MySQLConnectionChecker):\n    def __init__(self, config, name, db_info):\n        super().__init__(config, name)\n        self.user = db_info.get('user')\n        self.password = db_info.get('password')\n        self.host = db_info.get('host')\n        self.port = db_info.get('port')\n        self.ssl = db_info.get('ssl')\n        self.ssl_ca = db_info.get('ssl_ca')\n        self.ssl_cert = db_info.get('ssl_cert')\n        self.ssl_key = db_info.get('ssl_key')\n\n    def _to_mysql_table(self, dtype_dict, predicted_cols, columns):\n        subtype_map = {\n            dtype.integer: 'int',\n            dtype.float: 'double',\n            dtype.binary: 'bool',\n            dtype.date: 'Date',\n            dtype.datetime: 'Datetime',\n            dtype.binary: 'VARCHAR(500)',\n            dtype.categorical: 'VARCHAR(500)',\n            dtype.tags: 'VARCHAR(500)',\n            dtype.image: 'VARCHAR(500)',\n            dtype.video: 'VARCHAR(500)',\n            dtype.audio: 'VARCHAR(500)',\n            dtype.short_text: 'VARCHAR(500)',\n            dtype.rich_text: 'VARCHAR(500)',\n            dtype.array: 'VARCHAR(500)'\n        }\n\n        column_declaration = []\n        for name in columns:\n            try:\n                col_subtype = dtype_dict[name]\n                new_type = subtype_map[col_subtype]\n                column_declaration.append(f' `{name}` {new_type} ')\n                if name in predicted_cols:\n                    column_declaration.append(f' `{name}_original` {new_type} ')\n            except Exception as e:\n                log.error(f'Error: can not determine mysql data type for column {name}: {e}')\n\n        return column_declaration\n\n    def _escape_table_name(self, name):\n        return '`' + name.replace('`', '``') + '`'\n\n    def _query(self, query):\n        con = self._get_connnection()\n        with closing(con) as con:\n            cur = con.cursor(dictionary=True, buffered=True)\n            cur.execute(query)\n            res = True\n            try:\n                res = cur.fetchall()\n            except Exception:\n                pass\n            con.commit()\n\n        return res\n\n    def _get_connect_string(self, table):\n        user = f\"{self.config['api']['mysql']['user']}_{self.name}\"\n        password = self.config['api']['mysql']['password']\n        host = self.config['api']['mysql']['host']\n        port = self.config['api']['mysql']['port']\n\n        if password is None or password == '':\n            connect = f'mysql://{user}@{host}:{port}/mindsdb/{table}'\n        else:\n            connect = f'mysql://{user}:{password}@{host}:{port}/mindsdb/{table}'\n\n        return connect\n\n    def setup(self):\n        self._query(f'DROP DATABASE IF EXISTS {self.mindsdb_database}')\n        self._query(f'CREATE DATABASE IF NOT EXISTS {self.mindsdb_database}')\n\n        connect = self._get_connect_string('predictors')\n\n        q = f\"\"\"\n            CREATE TABLE IF NOT EXISTS {self.mindsdb_database}.predictors (\n                name VARCHAR(500),\n                status VARCHAR(500),\n                accuracy VARCHAR(500),\n                predict VARCHAR(500),\n                select_data_query VARCHAR(500),\n                external_datasource VARCHAR(500),\n                training_options VARCHAR(500),\n                key name_key (name)\n            ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';\n        \"\"\"\n        self._query(q)\n\n        connect = self._get_connect_string('commands')\n\n        q = f\"\"\"\n            CREATE TABLE IF NOT EXISTS {self.mindsdb_database}.commands (\n                command VARCHAR(500),\n                key command_key (command)\n            ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';\n        \"\"\"\n        self._query(q)\n\n    def register_predictors(self, model_data_arr):\n        for model_meta in model_data_arr:\n            name = model_meta['name']\n            predict = model_meta['predict']\n            if not isinstance(predict, list):\n                predict = [predict]\n            columns_sql = ','.join(self._to_mysql_table(\n                model_meta['dtype_dict'],\n                predict,\n                list(model_meta['dtype_dict'].keys())\n            ))\n            columns_sql += ',`when_data` varchar(500)'\n            columns_sql += ',`select_data_query` varchar(500)'\n            columns_sql += ',`external_datasource` varchar(500)'\n            for col in predict:\n                columns_sql += f',`{col}_confidence` double'\n                if model_meta['dtype_dict'][col] in (dtype.integer, dtype.float):\n                    columns_sql += f',`{col}_min` double'\n                    columns_sql += f',`{col}_max` double'\n                columns_sql += f',`{col}_explain` varchar(500)'\n\n            connect = self._get_connect_string(name)\n\n            self.unregister_predictor(name)\n            q = f\"\"\"\n                CREATE TABLE {self.mindsdb_database}.{self._escape_table_name(name)} (\n                    {columns_sql},\n                    index when_data_index (when_data),\n                    index select_data_query_index (select_data_query),\n                    index external_datasource_index (external_datasource)\n                ) ENGINE=FEDERATED CHARSET=utf8 CONNECTION='{connect}';\n            \"\"\"\n            self._query(q)\n\n    def unregister_predictor(self, name):\n        q = f\"\"\"\n            drop table if exists {self.mindsdb_database}.{self._escape_table_name(name)};\n        \"\"\"\n        self._query(q)\n\n    def get_row_count(self, query):\n        q = f\"\"\" \n            SELECT COUNT(*) as count\n            FROM ({query}) as query;\"\"\"\n        result = self._query(q)\n        return result[0]['count']\n\n    def get_columns(self,query):\n        q = f\"\"\"SELECT * from ({query}) LIMIT 1;\"\"\"\n        query_response = self._query(q)\n        if len(query_response) > 0:\n            columns = list(query_response[0].keys())\n            return columns\n        else:\n            return []\n    \n    def get_tables_list(self):\n        q= f\"\"\"\n            SHOW TABLES;\n            \"\"\"\n        result = self._query(q)\n        return result\n", "path": "mindsdb/integrations/mysql/mysql.py"}]}