Skip to main content

Posts

Showing posts from 2016

Common Table Expressions in MySQL

In a recent labs release a new feature was introduced by Oracle, or actually two very related new features were introduced. The first new feature is Common Table Expressions (CTEs), which is also known as WITH . The second feature is recursive CTEs, also known as WITH RECURSIVE . An example of WITH : WITH non_root_users AS (SELECT User, Host FROM mysql.user WHERE User<>'root') SELECT Host FROM non_root_users WHERE User = ? The non-CTE equivalent is this: SELECT Host FROM (SELECT User, Host FROM mysql.user WHERE User<>'root') non_root_users WHERE User = ? This makes it easier to understand the query, especially if there are many subqueries. Besides using regular subqueries or CTEs you could also put the subquery in a view, but this requires more privileges. It is also difficult to change the views later on as other quieries might have started to use them. But views are still very useful. You can make it easier for others to query data or you can ...

About Oracle MySQL and CVE-2016-6662

The issue On 12 September 2016 (three days ago) a MySQL security vulnerability was announced. The CVE id is CVE-2016-6662 . There are 3 claims: By setting malloc-lib in the configuration file access to an OS root shell can be gained. By using the general log a configuration file can be written in any place which is writable for the OS mysql user. By using SELECT...INTO DUMPFILE... it is possible to elevate privileges from a database user with the FILE privilege to any database account including root. How it is supposed to be used Find an SQL Injection in a website or otherwise gain access to a MySQL account. Now create a trigger file (requires FILE privilege) Now in the trigger or otherwise use SET GLOBAL general_log_file etc to create a my.cnf in the datadir with the correct privileges. Directly using SELECT...INTO DUMPFILE...won't work as that would result in the wrong permissions, which would cause mysqld/mysqld_safe to ignore that file. Now wait someone/somethi...

Visualizing the MySQL Bug Tide

On the MySQL Bugs website there are some tide stats available. These show rate of bug creation. I've put them in a graph: I made these with this IPython Notebook . There are more detailed graphs per version in the notebook. Update: The version in the notebook now uses the same range for the Y axis and has a marker for the GA dates of each release.

Re: JSON document fast lookup with MySQL 5.7

This is a response to the JSON document fast lookup with MySQL 5.7 article by Frederic Descamp. It is very easy to also use MySQL Workbench and the new GeoJSON support to actually show the features. My query: SELECT ST_GeomFromGeoJSON(feature->"$.geometry",2) AS feature  FROM test_features WHERE street='BEACH' ; The result:  

When simple SQL can be complex

I think SQL is a very simple language, but ofcourse I'm biased. But even a simple statement might have more complexity to it than you might think. Do you know what the result is of this statement? SELECT FALSE = FALSE = TRUE; scroll down for the answer. The answer is: it depends. You might expect it to return false because the 3 items in the comparison are not equal. But that's not the case. In PostgreSQL this is the result: postgres=# SELECT FALSE = FALSE = TRUE; ?column? ---------- t (1 row) So it compares FALSE against FALSE, which results in TRUE and then That is compared against TRUE, which results in TRUE. PostgreSQL has proper boolean literals . Next up is MySQL: mysql> SELECT FALSE = FALSE = TRUE; +----------------------+ | FALSE = FALSE = TRUE | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec) This is similar but it's slightly different. The result is 1 because in My...

Using Connector/J with Python

With Python you would normally use MySQL Connector/Python or the older MySQLdb to connect from Python to MySQL, but there are more options. There are also multiple Python implementations: CPython (the main implementation), PyPy , Jython and IronPython . PyPy tries to be faster than CPython by using a Just-in-Time compiler. Jython runs on the JVM and IronPython runs on the .NET CLR . Connector/Python by default (Without the C Extension) is a pure Python implementation and can work with most if not all implementations. And for MySQLdb there is a drop-in replacement called PyMySQL , which is a pure python implementation. So there are many options already. But for at least Jython it is also possible to use a Java (JDBC) driver. But why would you use a different Python implementation? There are multiple reasons for that: Speed. PyPy can be faster and Jython has no Global Interpreter Lock (GIL) , which can allow for more concurrent execution. To access 'native' code. e.g. ca...

The performance of TLS with MySQL Connector/Python

I've ran a simple test to see the performance impact of TLS on MySQL connections with MySQL Connector/Python The test results are in this Jupyter notebook . TL;DR: Try to reuse connections if you use TLS Establishing TLS connections is expensive (server & client) Improved performance might be possible in the future by using TLS Tickets Not tested: Difference between YaSSL and OpenSSL Difference between Ciphersuites Performance of larger resultsets and queries