diff --git a/lib/SimpleSAML/Database.php b/lib/SimpleSAML/Database.php
index ab5ddc2c71c1eac8a11140dfe315b442685331a8..8e267790efcf3c27eaf5e1ae608a45ccb9608300 100644
--- a/lib/SimpleSAML/Database.php
+++ b/lib/SimpleSAML/Database.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 namespace SimpleSAML;
 
+use Exception;
 use PDO;
 use PDOException;
 use PDOStatement;
@@ -164,7 +165,7 @@ class Database
 
             return $db;
         } catch (PDOException $e) {
-            throw new \Exception("Database error: " . $e->getMessage());
+            throw new Exception("Database error: " . $e->getMessage());
         }
     }
 
@@ -227,7 +228,7 @@ class Database
             return $query;
         } catch (PDOException $e) {
             $this->lastError = $db->errorInfo();
-            throw new \Exception("Database error: " . $e->getMessage());
+            throw new Exception("Database error: " . $e->getMessage());
         }
     }
 
@@ -247,7 +248,7 @@ class Database
             return $db->exec($stmt);
         } catch (PDOException $e) {
             $this->lastError = $db->errorInfo();
-            throw new \Exception("Database error: " . $e->getMessage());
+            throw new Exception("Database error: " . $e->getMessage());
         }
     }
 
@@ -291,4 +292,15 @@ class Database
     {
         return $this->lastError;
     }
+
+
+    /**
+     * Return the name of the PDO-driver
+     *
+     * @return string
+     */
+    public function getDriver(): string
+    {
+        return $this->dbPrimary->getAttribute(PDO::ATTR_DRIVER_NAME);
+    }
 }
diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
index f662f5138e5caa39054f7eae0e4f3ebee99f5057..bbd5d99e3a7b2c8d1dcd11b77d2cf7901659e1d4 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php
@@ -279,18 +279,28 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource
     {
         $stmt = 0;
         $fine = true;
+        $driver = $this->db->getDriver();
+
+        $text = 'TEXT';
+        if ($driver === 'mysql') {
+            $text = 'MEDIUMTEXT';
+        }
+
         foreach ($this->supportedSets as $set) {
             $tableName = $this->getTableName($set);
-            $rows = $this->db->write(
-                "CREATE TABLE IF NOT EXISTS $tableName (entity_id VARCHAR(255) PRIMARY KEY NOT NULL, entity_data " .
-                "TEXT NOT NULL)"
-            );
+            $rows = $this->db->write(sprintf(
+                "CREATE TABLE IF NOT EXISTS $tableName (entity_id VARCHAR(255) PRIMARY KEY NOT NULL, "
+                    . "entity_data %s NOT NULL)",
+                $text
+            ));
+
             if ($rows === false) {
                 $fine = false;
             } else {
                 $stmt += $rows;
             }
         }
+
         if (!$fine) {
             return false;
         }
diff --git a/tests/lib/SimpleSAML/DatabaseTest.php b/tests/lib/SimpleSAML/DatabaseTest.php
index cfafb15cdcedab3d48085db62c1c8461cabff6ed..b3305ab4395b09987ee18465cbb9adc777caebee 100644
--- a/tests/lib/SimpleSAML/DatabaseTest.php
+++ b/tests/lib/SimpleSAML/DatabaseTest.php
@@ -222,6 +222,13 @@ class DatabaseTest extends TestCase
         $this->assertEquals($prefix . $table, $pftable, "Did not properly apply the table prefix");
     }
 
+    /**
+     * @test
+     */
+    public function testGetDriver(): void
+    {
+        $this->assertEquals('sqlite', $this->db->getDriver());
+    }
 
     /**
      * @test