Skip to content

Instantly share code, notes, and snippets.

@Kreshnik
Last active April 12, 2017 04:34
Show Gist options
  • Save Kreshnik/4bd164572e11df7f96e4 to your computer and use it in GitHub Desktop.
Save Kreshnik/4bd164572e11df7f96e4 to your computer and use it in GitHub Desktop.
Gulp task to create a MySQL database
// Required npm packages: gulp, gulp-shell, gulp-prompt
// Usage: gulp db:create
var util = require('util');
var gulp = require('gulp');
var shell = require('gulp-shell');
var prompt = require('gulp-prompt');
gulp.task('db:create', function() {
gulp.src('').pipe(
prompt.prompt([{
type: 'input',
name: 'username',
message: 'Please enter your mysql username'
}, {
type: 'password',
name: 'password',
message: 'Please enter your mysql password'
}, {
type: 'input',
name: 'databaseName',
message: 'Enter the name of the database to create'
}], function(response) {
var shellCommand;
if (response.password == '') {
shellCommand = util.format('mysql -u %s -e "CREATE DATABASE %s"', response.username, response.databaseName)
} else {
shellCommand = util.format('mysql -u %s -p %s -e "CREATE DATABASE %s"', response.username, response.password, response.databaseName);
}
gulp.src('').pipe(shell([shellCommand]));
console.log('\n\x1b[32m%s\x1b[0m', 'Database created!');
}));
});
Copy link

ghost commented Apr 2, 2017

Hello,
I have a question how can i work with PHP and MySQL database using gulp?

@Kreshnik
Copy link
Author

Kreshnik commented Apr 2, 2017

Sorry I don't understand your question. What exactly do you want to achieve?

@Khaleel
Copy link

Khaleel commented Apr 12, 2017

I think he wants a WAMP/AMMPS sort of setup whereby Gulp and BrowserSync etc manage MySQL and PHP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment