blob: 9899f631116712b9438f68244ac70d57f66c8c8b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
);
|