brew 安装 mysql5.7_Mac——brew替换源地址安装配置mysql@5.7版本
問題描述:使用brew方式安裝mysql,存在以下問題:1.由于mysql已經升級到8.x版本,會默認安裝8.x版本,會對之前部分特性不友好支持;2.brew默認安裝源下載響應時間非常慢,下載時間過長容易超時;
問題解決:問題一通過brew search mysql可以查看到是有歷史版本可以下載的包括經典的5.7版本;
問題二需要更換brew源地址,具體更換源地址如下:
問題延伸:網上搜索大家都說跳轉到/usr/local目錄下使用git remote操作,結果如下:
$ git remote -v
fatal: Not a git repository (or any of the parent directories): .git
這就很無語了,后來終于找到另一種姿勢(使用環境變量去找);
替換以下幾個鏡像源:
替換為中科大的鏡像:
替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替換成功后更新下源:
brew update
對于bash用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
對于zsh用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
也可以選擇替換清華大學鏡像(和上邊部分效果相同):
替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
brew update
使用homebrew-science或者homebrew-python還需要替換
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-science"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-science.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-python"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-python.git
brew update
對于bash用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
對于zsh用戶:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
替換好brew源地址安裝mysql@5.7就會輕松很多;
brew源配置生效后使用brew install mysql@5.7安裝即可;
安裝完成后提示如下:
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 #運行連接
mysql@5.7 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 mysql@5.7 first in your PATH run: #配置環境變量
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
For compilers to find mysql@5.7 you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib" #想要系統編譯運行認識mysql@5.7配置環境變量
export 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 #啟動安裝后的mysql數據庫
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql@5.7/bin/mysql.server start #通過配置文件啟動mysql數據庫
根據安裝后提示信息第一步配置環境變量:
家目錄下,vi .bashprofile文件,將安裝后提示的:
export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"
加入到.bash_profile文件中,加入保存后使用source .bashprofile使配置到環境變量生效;
完成后使用:brew services start mysql@5.7或者你根據配置文件啟動mysql數據庫,服務啟動后開始初始化配置;
運行: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?
Press y|Y for Yes, any other key for No: k //是否采用mysql密碼安全檢測插件,我本地使用果斷拒絕了,因為密碼檢查插件要求密碼復雜程度高,大小寫字母+數字+字符等
Please set the password for root here. // 首次使用自帶配置腳本,設置root密碼
New password:
Re-enter new password:
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.
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.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y //是否禁止遠程登錄
Success.
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.
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!
配置完成,使用mysql -uroot -p,然后輸入配置到root密碼登陸到mysql數據庫;
總結
以上是生活随笔為你收集整理的brew 安装 mysql5.7_Mac——brew替换源地址安装配置mysql@5.7版本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用数据的商业智能分析工具
- 下一篇: 2021-10-24