mac安裝mysql

前言:

因?yàn)橛胢ac開發(fā),很多工具不是很熟練,這里做個(gè)筆記,以防以后再次入坑?。。?/p>


安裝方式一:用dmg鏡像安裝

1、安裝

下載好mysql MAC版安裝包,常規(guī)步驟安裝,安裝過程中會(huì)出現(xiàn)如下提示:

2018-04-22T08:07:19.044013Z 1 [Note] A temporary password is generated for root@localhost: TfrNnt9!k1xi

其中TfrNnt9!k1xi 是初始密碼,最好先記?。?/p>

2、登陸

但是在終端命令行 登陸mysql

mysql -u root -p

提示:-bash: mysql: command not found

遇上-bash: mysql: command not found的情況別著急,這個(gè)是因?yàn)?usr/local/bin目錄下缺失mysql導(dǎo)致,只需建立軟鏈接,即可以解決:

把mysql安裝目錄,比如MYSQLPATH/bin/mysql,映射到/usr/local/bin目錄下:

cd /usr/local/bin

ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql

接下來登陸就OK啦(完事?。?/p>

3、修改密碼
在MySQL8.0.4以前,執(zhí)行

SET PASSWORD=PASSWORD('修改的密碼'); 

即可修改密碼。

如果mysql是8.0版本以上,這樣默認(rèn)是不行的。因?yàn)橹埃琈ySQL的密碼認(rèn)證插件是“mysql_native_password”,而現(xiàn)在使用的是“caching_sha2_password”。

因?yàn)楫?dāng)前有很多數(shù)據(jù)庫工具和鏈接包都不支持“caching_sha2_password”,為了方便,我暫時(shí)還是改回了“mysql_native_password”認(rèn)證插件。

在MySQL中執(zhí)行命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密碼';

總結(jié):

其實(shí)鏡像安裝非常簡(jiǎn)單,只是在映射mysql指令的時(shí)候需要燒點(diǎn)腦子。


安裝方式二:用Homebrew進(jìn)行安裝

最近發(fā)現(xiàn)mac上一個(gè)神奇工具 Homebrew(包缺失管理),就像maven管理jar包的依賴一樣,Homebrew幫忙管理各種工具,真是太方便。Homebrew的常用指令。

安裝mysql:brew install mysql
feideMacBook-Air:~ fei$ brew install mysql@5.7
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.23.high_sierra.
Already downloaded: /Users/fei/Library/Caches/Homebrew/mysql@5.7-5.7.23.high_sierra.bottle.tar.gz
==> Pouring mysql@5.7-5.7.23.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.23/bin/mysqld --initialize-insecure --user=fei
==> Caveats
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

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/mysql@5.7/lib
    CPPFLAGS: -I/usr/local/opt/mysql@5.7/include


To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
??  /usr/local/Cellar/mysql@5.7/5.7.23: 317 files, 234.4MB

看看輸出的提示,剩下的該怎么操作其實(shí)brew提示的很清楚了?。。?/p>

對(duì)mysql進(jìn)行初始化操作:mysql_secure_installation
$ mysql_secure_installation
 
Securing the MySQL server deployment.
 
Connecting to MySQL using a blank password.
 
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
 // 這個(gè)選yes的話密碼長度就必須要設(shè)置為8位以上,但我只想要6位的
Press y|Y for Yes, any other key for No: N   
Please set the password for root here.
 
New password:            // 設(shè)置密碼
 
Re-enter new password:     // 再一次確認(rèn)密碼
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
 // 移除不用密碼的那個(gè)賬戶
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    
Success.
 
 
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
 //是否禁止遠(yuǎn)程登錄
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
 
 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
 
 // 是否刪除test庫
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.
 
 - Removing privileges on test database...
Success.
 
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
 
All done!

OK!這樣brew提示中的第一步就完成!接下來就可以嘗試登陸了

登陸mysql:mysql -u root -p
啟動(dòng)mysql:brew services start mysql@5.7
停止mysql:brew services stop mysql@5.7
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 最近沒事學(xué)習(xí)python爬蟲,其中需要將數(shù)據(jù)保存到數(shù)據(jù)庫中,于是就研究了一下怎么在mac中使用MySQL,中間也是...
    水丿果糖閱讀 10,820評(píng)論 0 5
  • 1.使用安裝包安裝mysql(網(wǎng)上下載實(shí)在是太慢了,需要安裝包的可以在文章底部留言,我發(fā)給您) 雙擊打開安裝文件 ...
    豬豬9527閱讀 660評(píng)論 0 2
  • 1.使用安裝包安裝mysql(網(wǎng)上下載實(shí)在是太慢了,需要安裝包的可以在文章底部留言,我發(fā)給您) 雙擊打開安裝文件 ...
    Jack問閱讀 13,396評(píng)論 5 4
  • 原題 用 O(1) 時(shí)間檢測(cè)整數(shù) n 是否是 2 的冪次。 樣例n=4,返回 true;n=5,返回 false....
    Jason_Yuan閱讀 262評(píng)論 0 0
  • 在我青春的時(shí)候,我覺得我沒有童年。在我已經(jīng)遠(yuǎn)離青春的時(shí)候,我一直都在欺騙自己,我正青春。 1. 畢業(yè)初到H小城工作...
    平果綠閱讀 324評(píng)論 3 0

友情鏈接更多精彩內(nèi)容