Why is MyISAM the default table type in MySQL and what are its advantages?

MyISAM is the default table type in MySQL because it is simple, fast, and efficient for read-heavy applications. It offers full-text search capabilities and supports table-level locking, making it suitable for applications that require high-speed reads and can tolerate occasional data inconsistencies. To change the default table type in MySQL to InnoDB, you can modify the my.cnf configuration file and set the default_storage_engine variable to InnoDB. Here is an example PHP code snippet that demonstrates this:

$dsn = 'mysql:host=localhost;dbname=my_database';
$username = 'username';
$password = 'password';

try {
    $pdo = new PDO($dsn, $username, $password);
    $pdo->exec("SET GLOBAL default_storage_engine = 'InnoDB';");
    echo "Default table type changed to InnoDB";
} catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}