-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySQL_setup
More file actions
33 lines (25 loc) · 1.01 KB
/
MySQL_setup
File metadata and controls
33 lines (25 loc) · 1.01 KB
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
27
28
29
30
31
32
33
$ sudo apt install mysql-server -y
$ sudo mysql >> to open mysql terminal
-- Sets local root user's password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password in quotes';
-- Reloads to apply changes & exit mysql:
FLUSH PRIVILEGES;
EXIT;
$ sudo mysql -u root -p >> enter password declared above to open & access mysql
-- To create database if not exisiting already:
CREATE DATABASE IF NOT EXISTS crud_app;
-- Switch to database:
USE crud_app;
-- To drop table if needed (optional safety clean up):
DROP TABLE IF EXISTS users;
-- To create 'users' table with proper structure:
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role ENUM('admin', 'viewer') NOT NULL DEFAULT 'viewer',
is_active TINYINT(1) DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
exit; (exit mysql terminal)