Author: Sergei

  • MariaDB 10.1.1: Compound statements

    Every now and then there is a need to execute certain SQL statements conditionally. Easy, if you do it from your PHP (or Java or whatever) application. But if all you have is pure SQL? There are two techniques that MariaDB and MySQL use in the mysql_fix_privilege_tables.sql script (applied by mysql_upgrade tool).

    1. Create a stored procedure with IF statements inside, call it once and drop it. This requires the user to have the CREATE ROUTINE privilege and mysql.proc table must exist and be usable (which is not necessarily true — we’re doing it from mysql_upgrade, right?).
    2. Use dynamic SQL, like
      SET @str = IF (@have_csv = 'YES',
                     'CREATE TABLE IF NOT EXISTS general_log (
                        event_time TIMESTAMP(6) NOT NULL,
                        user_host MEDIUMTEXT NOT NULL,
                        thread_id BIGINT(21) UNSIGNED NOT NULL,
                        server_id INTEGER UNSIGNED NOT NULL,
                        command_type VARCHAR(64) NOT NULL,
                        argument MEDIUMTEXT NOT NULL
                      ) engine=CSV CHARACTER SET utf8 comment="General log"',
                     'SET @dummy = 0');
      
      PREPARE stmt FROM @str;
      EXECUTE stmt;
      DROP PREPARE stmt;
      

      which is not very readable and doesn’t work well if you need to execute many statements conditionally.

  • MariaDB 10.1.1: no more .frm’s for performance_schema tables

    Yes! In MariaDB 10.1.1 tables in PERFORMANCE_SCHEMA do not use .frm files. These files are not created, not read — in fact, PERFORMANCE_SCHEMA tables never touch the disk at all.

    This became possible due to a lesser-known feature of MariaDB — new table discovery (“old table discovery” was implemented in MySQL for NDB Cluster in 2004), implemented in MariaDB 10.0.2. Instead of reading and parsing .frm files, MariaDB simply asks PERFORMANCE_SCHEMA table, what structure it has, and because these tables […]

  • MariaDB 10.1.1: default roles

    As you all know MariaDB supported roles since the MariaDB release 10.0.5. They were implemented almost exactly as specified in the SQL Standard 2003, features T331 “Basic roles” and T332 “Extended Roles”.

    But we were often hearing complains, users were not satisfied with purely standard set of features. In particular, the standard specified that one had to do

    to be able to use privileges, granted to the role foobar. This was not always convenient and sometimes not even possible (imagine, […]

  • Dynamic replication filters — our wheel will be square!

    This is both hilarious and sad. The new MySQL 5.7 milestone release presents a new feature — replication filters are now dynamic. This is a great and long awaited feature, no doubt about it.

    In short, for years MySQL slaves could filter the incoming stream of replication events based on the database or table name these events were applicable to. These filters were configured using the my.cnf file (or command-line), in particular with the following variables:

    Naturally, users wanted to be […]

  • Unbreakable MySQL?

    I’m getting more and more concerned about the current Oracle approach to MySQL security. And the fact that I was solely responsible for the security@mysql.com for about ten years, doesn’t make it easier, on the contrary, it only emphasizes changes in the attitude.

    Starting from the obvious — somewhat slower response to critical bug fixes, which can be expected, Oracle is a big company, right? Very little information about security vulnerabilities is disclosed, CPUs are carefully stripped from anything that […]

  • Disappearing test cases or did another part of MySQL just become closed source?

    About a week ago I was looking at MySQL 5.5.27, and noticed a curious thing. Despite the fact that the new MySQL release contained its usual share of bug fixes, not a single one of them was accompanied with a test case.

    Now, let me tell you something about tests. For many years MySQL was using its own testing framework, called mysql-test. The first version was written as early as 1999. Over the years it has accumulated a lot of […]

  • MariaDB: Improve Security with Two-Step Verification

    In this primer I will show how to improve the security of your MariaDB installation by using two-step verification and how to use it from your Windows GUI client.

    Let’s suppose you have your data in MariaDB, installed, say, on Ubuntu. And your users connect to it to run ad hoc queries, using some sort of a Windows GUI client. You don’t want them to write the access password on post-it notes or have it auto-entered by the client. And […]

  • Writing a MariaDB PAM Authentication Plugin

    As you may know, since version 5.2.0 (released in April 2010) we support Pluggable Authentication. Using this feature one can implement an arbitrary user authentication and account management policy, completely replacing built-in MariaDB authentication with its username/password combination and mysql.user table.

    Also, as you might have heard, Oracle has recently released a PAM authentication plugin for MySQL. Alas, this plugin will not run on MariaDB — although the MySQL implementation of pluggable authentication is based on ours, the API is incompatible. […]