Last active
June 9, 2018 19:06
-
-
Save 0guzhan/40e6bc8c1fbc620a03d3c83a4b6a84d0 to your computer and use it in GitHub Desktop.
Mysql Database Schema SQL Generator e.g. [./create_schema.pl database_name username password]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use feature qw/say/; | |
my $sql_create_database = <<'SQL_CREATE_DATABASE'; | |
CREATE DATABASE IF NOT EXISTS database_name | |
DEFAULT CHARACTER SET = utf8mb4 | |
DEFAULT COLLATE utf8mb4_unicode_ci; | |
SQL_CREATE_DATABASE | |
my $sql_create_user = <<'SQL_CREATE_USER'; | |
CREATE USER IF NOT EXISTS 'username'@'%' IDENTIFIED BY 'password'; | |
SQL_CREATE_USER | |
my $sql_grant_user = <<'SQL_GRANT_USER'; | |
GRANT ALL ON database_name.* TO 'username'@'%'; | |
SQL_GRANT_USER | |
my $sql_flush_priviliges = <<'SQL_FLUSH_PRIVILIGES'; | |
FLUSH PRIVILEGES; | |
SQL_FLUSH_PRIVILIGES | |
my $database_name = shift(@ARGV); | |
die "database_name is not defined" unless $database_name; | |
my $username = shift(@ARGV); | |
die "username is not defined" unless $username; | |
my $password = shift(@ARGV); | |
die "password is not defined" unless $password; | |
$sql_create_database =~ s/database_name/$database_name/g; | |
$sql_create_user =~ s/username/$username/g; | |
$sql_create_user =~ s/password/$password/g; | |
$sql_grant_user =~ s/database_name/$database_name/g; | |
$sql_grant_user =~ s/username/$username/g; | |
print $sql_create_database; | |
print $sql_create_user; | |
print $sql_grant_user; | |
print $sql_flush_priviliges; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment