Return the version of a MySQL server using the output from the ``SELECT VERSION()`` query. CLI Example: .. code-block:: bash salt '*' mysql.version
(**connection_args)
| 1007 | |
| 1008 | |
| 1009 | def version(**connection_args): |
| 1010 | """ |
| 1011 | Return the version of a MySQL server using the output from the ``SELECT |
| 1012 | VERSION()`` query. |
| 1013 | |
| 1014 | CLI Example: |
| 1015 | |
| 1016 | .. code-block:: bash |
| 1017 | |
| 1018 | salt '*' mysql.version |
| 1019 | """ |
| 1020 | if "mysql.version" in __context__: |
| 1021 | return __context__["mysql.version"] |
| 1022 | |
| 1023 | dbc = _connect(**connection_args) |
| 1024 | if dbc is None: |
| 1025 | return "" |
| 1026 | cur = dbc.cursor() |
| 1027 | qry = "SELECT VERSION()" |
| 1028 | try: |
| 1029 | _execute(cur, qry) |
| 1030 | except MySQLdb.OperationalError as exc: |
| 1031 | err = "MySQL Error {}: {}".format(*exc.args) |
| 1032 | __context__["mysql.error"] = err |
| 1033 | log.error(err) |
| 1034 | return "" |
| 1035 | |
| 1036 | try: |
| 1037 | __context__["mysql.version"] = salt.utils.data.decode(cur.fetchone()[0]) |
| 1038 | return __context__["mysql.version"] |
| 1039 | except IndexError: |
| 1040 | return "" |
| 1041 | |
| 1042 | |
| 1043 | def slave_lag(**connection_args): |
no test coverage detected