main
HerrHase 1 year ago
parent b5c5353aa5
commit b6e43dd504

@ -15,23 +15,14 @@ const log = console.log
*/
const user = {
name: undefined,
name: 'root',
password: undefined
}
user.name = await input({
message: 'Root:',
async validate(value) {
if (!value) {
return 'Required!'
}
return true
}
})
log(chalk.red('Mariadb Create Database...'))
user.password = await password({
message: 'Password:',
message: 'Enter Root Password:',
mask: '*',
async validate(value) {
if (!value) {

@ -1,5 +1,8 @@
import mysql from 'mysql2/promise'
import { input, password } from '@inquirer/prompts'
import chalk from 'chalk'
const log = console.log
/**
* mariadb-drop.js
@ -11,12 +14,15 @@ import { input, password } from '@inquirer/prompts'
*/
const user = {
name: undefined,
name: 'root',
password: undefined
}
user.name = await input({
message: 'Root:',
log(chalk.cyan('Mariadb drop Database...'))
user.password = await password({
message: 'Enter Root Password:',
mask: '*',
async validate(value) {
if (!value) {
return 'Required!'
@ -26,9 +32,8 @@ user.name = await input({
}
})
user.password = await password({
message: 'Password:',
mask: '*',
const database = await input({
message: 'Database:',
async validate(value) {
if (!value) {
return 'Required!'
@ -46,38 +51,17 @@ const connection = await mysql.createConnection({
password: user.password
})
const database = {
name: 'db',
user: 'u'
}
database.name += generator.generate({
length: 15,
numbers: true
})
// create database
database.user += generator.generate({
length: 15,
numbers: true
})
const [results ] = await connection.query("SELECT User FROM mysql.db WHERE Db = '" + database + "'")
database.password = generator.generate({
length: 30,
numbers: true
results.forEach(async (entity) => {
await connection.query("DROP USER IF EXISTS '" + entity.User + "'@localhost");
await connection.query("DROP USER IS EXISTS '" + entity.User + "'@'%'");
})
// create database
await connection.query('CREATE DATABASE ' + database.name + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci')
await connection.query("CREATE USER " + database.user + "@'localhost' IDENTIFIED BY '" + database.password + "'")
await connection.query("CREATE USER " + database.user + "@'%' IDENTIFIED BY '" + database.password + "'")
await connection.query("GRANT ALL PRIVILEGES ON " + database.name + ".* TO " + database.user + "@localhost")
await connection.query("FLUSH PRIVILEGES")
await connection.query("DROP DATABASE IF EXISTS " + database);
connection.destroy()
// show name, user and passwort
console.log(database.name)
console.log(database.user)
console.log(database.password)
log(chalk.green('Database ' + database + ' droped!'))

Loading…
Cancel
Save