bhylu.com

Advertisements

MySQL CREATE and DROP DATABASE

Treat schema creation and deletion as deliberate administrative actions with a verified target.

How it works

A schema groups tables and other objects. CREATE DATABASE can choose its default character set and collation. DROP DATABASE removes its objects and data; it is not an ordinary cleanup step for an application request. This lab creates a specially named disposable schema, confirms its presence and drops only that newly created schema. Do not add IF NOT EXISTS here: an existing name must stop the exercise rather than invite deletion of someone else’s data.

Run in a disposable MySQL lab

Use Oracle MySQL 8.4 with InnoDB, not Bhylu’s SQLite playground. The examples were reviewed on MySQL 8.4.8. XAMPP may provide MariaDB, which has different feature and collation behaviour. Check your actual server before running the script. These lessons do not require a change to Bhylu’s PHP, Apache or normal database service.

  1. On a separate lab instance, create the empty bhylu_mysql_lab schema. Stop if it already exists; do not overwrite an existing database.
  2. Select that schema and import the complete repair-parts seed once. It sets the documented session mode, utf8mb4 collation, UTC and English date-name locale.
  3. Run this lesson in a fresh copy of the seed, not after another lesson’s writes. Use the command-line client or a compatible editor. DELIMITER lines are client instructions for stored-program examples.

Download this complete lesson script. Its setup is the linked seed; review the dataset before changing it. Administrative and destructive examples are restricted to the specifically named disposable objects. Every script repeats the session settings because each new connection has its own session. No MySQL browser runner is currently available.

Example

lesson.sql

SET NAMES utf8mb4 COLLATE utf8mb4_0900_ai_ci;
SET SESSION sql_mode = 'STRICT_TRANS_TABLES,ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
SET SESSION time_zone = '+00:00';
SET SESSION lc_time_names = 'en_US';
CREATE DATABASE bhylu_mysql_disposable CHARACTER SET utf8mb4;
SELECT COUNT(*) FROM information_schema.schemata
WHERE schema_name = 'bhylu_mysql_disposable';
CREATE TABLE bhylu_mysql_disposable.retired_sample (id INT PRIMARY KEY);
DROP TABLE bhylu_mysql_disposable.retired_sample;
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = 'bhylu_mysql_disposable';
DROP DATABASE bhylu_mysql_disposable;
SELECT COUNT(*) FROM information_schema.schemata
WHERE schema_name = 'bhylu_mysql_disposable';

Expected result

1
0
0

Run this only on a disposable server and stop immediately if CREATE fails. The active lesson schema stays separate; no USE statement switches into the temporary administrative target. A production retirement needs a retention decision, dependency review and tested recovery plan. DDL can cause implicit commits, so a surrounding transaction is not a reliable undo button for schema deletion.

Use the official MySQL 8.4 reference for statement contracts and version details.

Advertisements