diff --git a/lib/github/kv.rb b/lib/github/kv.rb
index <HASH>..<HASH> 100644
--- a/lib/github/kv.rb
+++ b/lib/github/kv.rb
@@ -136,7 +136,7 @@ module GitHub
       validate_expires(expires) if expires
 
       rows = kvs.map { |key, value|
-        [key, value, GitHub::SQL::NOW, GitHub::SQL::NOW, expires || GitHub::SQL::NULL]
+        [key, GitHub::SQL::BINARY(value), GitHub::SQL::NOW, GitHub::SQL::NOW, expires || GitHub::SQL::NULL]
       }
 
       encapsulate_error do
@@ -225,7 +225,7 @@ module GitHub
           DELETE FROM key_values WHERE `key` = :key AND expires_at <= NOW()
         SQL
 
-        sql = GitHub::SQL.run(<<-SQL, :key => key, :value => value, :expires => expires || GitHub::SQL::NULL, :connection => connection)
+        sql = GitHub::SQL.run(<<-SQL, :key => key, :value => GitHub::SQL::BINARY(value), :expires => expires || GitHub::SQL::NULL, :connection => connection)
           INSERT IGNORE INTO key_values (`key`, value, created_at, updated_at, expires_at)
           VALUES (:key, :value, NOW(), NOW(), :expires)
         SQL
Use binary escaping for value

Since the `value` is a binary blob in the MySQL database, we also need to ensure we escape it as binary. This prevent potential query warnings (or errors if MySQL is configured that way) for when 4 byte UTF-8 characters get sent to a binary field but with string escaping.