Skip to content

Commit 101f1a1

Browse files
committed
Add MySQL db creation
1 parent 51faaf4 commit 101f1a1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

recipe/provision/databases.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
return ask(' DB name: ');
1616
});
1717

18+
set('db_user', function () {
19+
return ask(' DB user: ', 'deployer');
20+
});
21+
1822
set('db_password', function () {
1923
return askHiddenResponse(' DB password: ');
2024
});
@@ -25,16 +29,23 @@
2529
if ($dbType === 'none') {
2630
return;
2731
}
28-
get('db_name');
29-
get('db_password');
3032
invoke('provision:' . $dbType);
3133
})
3234
->limit(1);
3335

3436

3537
desc('Provision MySQL');
3638
task('provision:mysql', function () {
37-
run('apt-get install -y mysql-server', ['env' => ['DEBIAN_FRONTEND' => 'noninteractive']]);
39+
//run('apt-get install -y mysql-server', ['env' => ['DEBIAN_FRONTEND' => 'noninteractive']]);
40+
get('db_user');
41+
get('db_name');
42+
get('db_password');
43+
run("mysql --user=\"root\" -e \"CREATE USER IF NOT EXISTS '{{db_user}}'@'0.0.0.0' IDENTIFIED BY '%secret%';\"", ['secret' => get('db_password')]);
44+
run("mysql --user=\"root\" -e \"CREATE USER IF NOT EXISTS '{{db_user}}'@'%' IDENTIFIED BY '%secret%';\"", ['secret' => get('db_password')]);
45+
run("mysql --user=\"root\" -e \"GRANT ALL PRIVILEGES ON *.* TO '{{db_user}}'@'0.0.0.0' WITH GRANT OPTION;\"");
46+
run("mysql --user=\"root\" -e \"GRANT ALL PRIVILEGES ON *.* TO '{{db_user}}'@'%' WITH GRANT OPTION;\"");
47+
run("mysql --user=\"root\" -e \"FLUSH PRIVILEGES;\"");
48+
run("mysql --user=\"root\" -e \"CREATE DATABASE IF NOT EXISTS {{db_name}} character set UTF8mb4 collate utf8mb4_bin;\"");
3849
});
3950

4051
desc('Provision MariaDB');

0 commit comments

Comments
 (0)