安装MySQL
brew install mysql
可以通过
mysql.server startmysql.server stop 如果提示pid 不存在 sudo chown -R _mysql:_mysql /usr/local/var/mysql
来启动/停止,启动后默认应为空密码,可以通过mysqladmin设置一个密码
mysqladmin -uroot password "mypassword" 如果修改不能修改密码:
Here is the procedure to reset password of root user.
1) Stop mysql (Kill mysql process or run following command)
sudo /usr/local/mysql/support-files/mysql.server stop
2) Start it in safe mode
sudo mysqld_safe --skip-grant-tables
3) Open another terminal and run the following command (Keep last terminal open)
mysql -u root
4) Run the following command with suitable new password on the mysql console
For MySQL 5.7+:
mysql > UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
For earlier versions:
mysql > UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
5) mysql > FLUSH PRIVILEGES;
6) Quit from both terminals and open new terminal and connect to mysql with root user and new password
mysql -uroot -p
但是在操作的时候出现了空密码无法登入的情况,最终只能通过mysqld_safe来设置
sudo mysqld_safe --skip-grant-tablesmysql -u rootmysql> UPDATE mysql.user SET Password=PASSWORD('mypassword') WHERE User='root'; mysql> FLUSH PRIVILEGES;
最后将MySQL加入开机启动
cp /usr/local/Cellar/mysql/5.6.22/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/