From d3833d2a50371b5ebc989ca9b4a999a5f7f74c98 Mon Sep 17 00:00:00 2001 From: Georgi Nikolov Date: Fri, 17 Jan 2025 20:07:55 +0200 Subject: Added example mariadb code in php --- migrations/initial.sql | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 migrations/initial.sql (limited to 'migrations') diff --git a/migrations/initial.sql b/migrations/initial.sql new file mode 100644 index 0000000..9899f63 --- /dev/null +++ b/migrations/initial.sql @@ -0,0 +1,26 @@ +SET @username = 'default'; +SET @password = 'Password1234'; + +-- Check if the user exists +SELECT COUNT(*) INTO @user_exists +FROM mysql.user +WHERE user = @username AND host = 'localhost'; + +-- Create the user if it does not exist +IF @user_exists = 0 THEN + CREATE USER @username@'localhost' IDENTIFIED BY @password; +END IF; + +GRANT ALL PRIVILEGES ON db.* TO @username@'localhost'; +FLUSH PRIVILEGES; + +-- Create the database if it does not exist +CREATE DATABASE IF NOT EXISTS db; +USE db; + +-- Create the users table if it does not exist +CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL +); -- cgit v1.2.3