Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
気軽にMysqlのdata_dirを作成して、スタートスクリプトとストップスクリプトと、ごく最低限のmy.cnfを生成します。
<?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
You can’t perform that action at this time.