Last active
December 19, 2015 22:39
-
-
Save uzulla/6028743 to your computer and use it in GitHub Desktop.
気軽にMysqlのdata_dirを作成して、スタートスクリプトとストップスクリプトと、ごく最低限のmy.cnfを生成します。
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
<?php | |
/* | |
mysql_data_setup.php | |
https://gist.github.com/uzulla/6028743 | |
HOW TO USE | |
========== | |
``` | |
cd ~/mysql-temp # create some dir. | |
php mysql_data_setup.php # make data_dir, create some script and my.cnf | |
#plz watch error. | |
cd ~/mysql-temp | |
./start_mysql.sh # start mysql | |
# something work...done! | |
./stop_mysql.sh # stop mysql | |
cd ~/ | |
rm -R ~/mysql-temp # delete all temp mysql data_dir. done! | |
``` | |
*/ | |
define("MYSQL_BASE_DIR", "/usr/local/mysql"); | |
define("PORT", 3306); | |
$cwd = (isset($argv[1])) ? $argv[1] : __DIR__; | |
$dir = realpath($cwd); | |
chdir($dir); | |
mkdir('mysql_data'); | |
$mysql_install_db = "mysql_install_db --datadir={$dir}/mysql_data --basedir=".MYSQL_BASE_DIR; | |
echo `$mysql_install_db`; | |
$start_mysql = "#!/bin/sh | |
mysqld_safe --defaults-file={$dir}/mysql_data/my.cnf &"; | |
file_put_contents('start_mysql.sh', $start_mysql); | |
chmod('start_mysql.sh', 0755); | |
$start_mysql = "#!/bin/sh | |
mysqladmin shutdown -u root --socket={$dir}/mysql_data/socket"; | |
file_put_contents('stop_mysql.sh', $start_mysql); | |
chmod('stop_mysql.sh', 0755); | |
$my_cnf = "[mysqld] | |
basedir = ".MYSQL_BASE_DIR." | |
datadir = {$dir}/mysql_data | |
socket = {$dir}/mysql_data/socket | |
port = ".PORT." | |
bind-address = 127.0.0.1"; | |
file_put_contents('mysql_data/my.cnf', $my_cnf); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment