為什么用brew安裝呢?
方便, 不用去官網(wǎng)找MySQL的各種版本, 而且各種版本會(huì)把你繞的挺暈的.
首先你要有個(gè)brew
brew install mysql
然后會(huì)出現(xiàn)下面一段話
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
我本來(lái)想用mysql_secure_installation
設(shè)置密碼的, 但是發(fā)生錯(cuò)誤, 只能換一種方式設(shè)置密碼.
首先啟動(dòng)MySQL服務(wù)
brew services start mysql
這種是后臺(tái)啟動(dòng)方式, 方便你下次使用MySQL服務(wù)的時(shí)候, 直接使用
然后登錄MySQL
mysql -u root
MySQL5.7以后會(huì)出現(xiàn)輸入update mysql.user set password=password('root') where user='root'
時(shí)提示ERROR 1054 (42S22): Unknown column 'password' in 'field list'
,原來(lái)是mysql數(shù)據(jù)庫(kù)下已經(jīng)沒(méi)有password
這個(gè)字段了,password
字段改成了authentication_string
.
接下來(lái)更新root密碼
update mysql.user set authentication_string=password('root') where user='root' ;
最會(huì)別忘了刷新權(quán)限
flush privileges;
?? 現(xiàn)在退出MySQL, 測(cè)試一下你設(shè)置的密碼吧!