為什么用brew安裝呢?
方便, 不用去官網找MySQL的各種版本, 而且各種版本會把你繞的挺暈的.
首先你要有個brew
brew install mysql
然后會出現下面一段話
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
我本來想用mysql_secure_installation
設置密碼的, 但是發生錯誤, 只能換一種方式設置密碼.
首先啟動MySQL服務
brew services start mysql
這種是后臺啟動方式, 方便你下次使用MySQL服務的時候, 直接使用
然后登錄MySQL
mysql -u root
MySQL5.7以后會出現輸入update mysql.user set password=password('root') where user='root'
時提示ERROR 1054 (42S22): Unknown column 'password' in 'field list'
,原來是mysql數據庫下已經沒有password
這個字段了,password
字段改成了authentication_string
.
接下來更新root密碼
update mysql.user set authentication_string=password('root') where user='root' ;
最會別忘了刷新權限
flush privileges;
?? 現在退出MySQL, 測試一下你設置的密碼吧!