From 1364cdd0576ac63342cb83fe1fba4322b8347141 Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Wed, 22 May 2019 01:12:08 +0300 Subject: [PATCH 1/4] Fix ErrorCodes. --- dbms/src/Common/ErrorCodes.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dbms/src/Common/ErrorCodes.cpp b/dbms/src/Common/ErrorCodes.cpp index f53f1f3bafa..bd797f5b71f 100644 --- a/dbms/src/Common/ErrorCodes.cpp +++ b/dbms/src/Common/ErrorCodes.cpp @@ -427,6 +427,7 @@ namespace ErrorCodes extern const int BAD_TTL_EXPRESSION = 450; extern const int BAD_TTL_FILE = 451; extern const int SETTING_CONSTRAINT_VIOLATION = 452; + extern const int MYSQL_CLIENT_INSUFFICIENT_CAPABILITIES = 453; extern const int OPENSSL_ERROR = 454; extern const int KEEPER_EXCEPTION = 999; @@ -437,8 +438,6 @@ namespace ErrorCodes extern const int CONDITIONAL_TREE_PARENT_NOT_FOUND = 2001; extern const int ILLEGAL_PROJECTION_MANIPULATOR = 2002; - - extern const int MYSQL_CLIENT_INSUFFICIENT_CAPABILITIES = 446; } } From 7af34954f9c08c48000fdd441cb01467a2a8918d Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Sat, 25 May 2019 19:11:54 +0300 Subject: [PATCH 2/4] Clearer message if the client doesn't have plugin sha256_password. --- dbms/programs/server/MySQLHandler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dbms/programs/server/MySQLHandler.cpp b/dbms/programs/server/MySQLHandler.cpp index 17918815db8..dda6a4eb736 100644 --- a/dbms/programs/server/MySQLHandler.cpp +++ b/dbms/programs/server/MySQLHandler.cpp @@ -224,6 +224,10 @@ void MySQLHandler::authenticate(const HandshakeResponse & handshake_response, co if (handshake_response.auth_plugin_name != Authentication::SHA256) { packet_sender->sendPacket(AuthSwitchRequest(Authentication::SHA256, scramble + '\0'), true); + if (in->eof()) + throw Exception( + "Client doesn't support authentication method " + String(Authentication::SHA256) + " used by ClickHouse", + ErrorCodes::MYSQL_CLIENT_INSUFFICIENT_CAPABILITIES); packet_sender->receivePacket(response); auth_response = response.value; LOG_TRACE(log, "Authentication method mismatch."); From c07bd87716292ffe1cc748ae3c4e2267d2213a5c Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Sat, 25 May 2019 19:14:15 +0300 Subject: [PATCH 3/4] Print "ClickHouse" when writing server's info at the start of the client session. --- dbms/programs/server/MySQLHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/programs/server/MySQLHandler.cpp b/dbms/programs/server/MySQLHandler.cpp index dda6a4eb736..d4de9d9d3f4 100644 --- a/dbms/programs/server/MySQLHandler.cpp +++ b/dbms/programs/server/MySQLHandler.cpp @@ -62,7 +62,7 @@ void MySQLHandler::run() * This plugin must do the same to stay consistent with historical behavior if it is set to operate as a default plugin. * https://github.com/mysql/mysql-server/blob/8.0/sql/auth/sql_authentication.cc#L3994 */ - Handshake handshake(server_capability_flags, connection_id, VERSION_STRING, scramble + '\0'); + Handshake handshake(server_capability_flags, connection_id, VERSION_STRING + String("-") + VERSION_NAME, scramble + '\0'); packet_sender->sendPacket(handshake, true); LOG_TRACE(log, "Sent handshake"); From a35d1e0b3dc26a55745e417507afd0144e7263e7 Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Sat, 25 May 2019 19:15:38 +0300 Subject: [PATCH 4/4] Allow using MariaDB as a client without exception. --- dbms/programs/server/MySQLHandler.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dbms/programs/server/MySQLHandler.cpp b/dbms/programs/server/MySQLHandler.cpp index d4de9d9d3f4..4647acd1e59 100644 --- a/dbms/programs/server/MySQLHandler.cpp +++ b/dbms/programs/server/MySQLHandler.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -353,8 +353,16 @@ void MySQLHandler::comQuery(const String & payload) std::function set_content_type = [&with_output](const String &) -> void { with_output = true; }; - ReadBufferFromMemory query(payload.data() + 1, payload.size() - 1); - executeQuery(query, *out, true, connection_context, set_content_type, nullptr); + + String query = payload.substr(1); + + // Translate query from MySQL to ClickHouse. + // This is a temporary workaround until ClickHouse supports the syntax "@@var_name". + if (query == "select @@version_comment limit 1") // MariaDB client starts session with that query + query = "select ''"; + + ReadBufferFromString buf(query); + executeQuery(buf, *out, true, connection_context, set_content_type, nullptr); if (!with_output) packet_sender->sendPacket(OK_Packet(0x00, client_capability_flags, 0, 0, 0), true); }