LoginSignup
19
24

More than 5 years have passed since last update.

MacにMySQLを導入する (Homebrewを使って)

Posted at

MySQLをインストール

brew install mysql

データベースの初期化

$ unset TMPDIR
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

とりあえず起動と停止

$ mysql.server start
$ mysql.server stop

ルートのパスワード変更

$ mysql.server start
$ mysqladmin -u root password 'new-password'

で、できるはずが、、、

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

なんで?

パスワード変更で Access denied と言われた時の対処

パスワードのリセットをしちゃいます。
safeモードで起動し直し。

$ mysql.server stop
$ mysqld_safe --skip-grant-tables &

で、ログインする。

$ mysql -u root
mysql >

ログインできたらmysqlデータベースのuserテーブルを再構築しちゃう

mysql> use mysql;
mysql> truncate table user;
mysql> flush privileges;
mysql> grant all privileges on *.* to root@localhost identified by 'password' with grant option;
mysql> flush privileges;
mysql> quit;

そしてMySQLを再起動してログイン

$ mysql -u root -p
Enter password: password
mysql >

自動起動設定

$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

homebrew.mxcl.mysql.plist を開いてKeepAliveをNOにしておくのもいいよ。

my.cnfの設置

http://www.karakaram.com/install-mysql56-homebrew を参考にしてみます。

19
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
24