For deploying an application, I’m required to create a database for basic user authentication. To automate the process, I’ve written a MySQL batch file:
grant all on jetty.* to 'jetty'@'localhost' identified by 'jetty';
create database if not exists jetty;
use jetty;
create table if not exists users
(
id int unsigned not null auto_increment,
username varchar(100) not null,
password binary(60) not null,
primary key(id),
unique(username)
);
create table if not exists roles
(
id int unsigned not null auto_increment,
role varchar(100) not null,
primary key(id),
unique(role)
);
create table if not exists user_roles
(
user_id int unsigned not null,
role_id int unsigned not null,
unique(user_id, role_id),
index(user_id)
);
insert into users(username, password) values('jetty', $2a$10$YX3cYqn9nHmCOmPZBHXrQ.2nxrktB3CRYG8tXmBmmWvrDKU8uwRSe');
I’ve been doing this for the first time, so I’m quite sure there are some things I might not get right. Is it actually a good idea to populate the users table with one user? To log into my application, there needs to be some account, still I’m not quite sure.
Another thing that bugs me is the grant statement. I wonder if grant all may not be restrictive enough.
Also, should I check for if not exists on every table I’m going to create?
Are there any best practices concerning batch scripts?
Be sure to make a backup before
DROPing those tables though.Good luck.