我是brew安裝的MySQL胆建,所以刪除起來很麻煩,各種殘留項都沒有辦法解決兼丰,最后各種查資料花了三個小時總算搞定了玻孟!分享一下我的經(jīng)歷,希望能夠幫助到其他小伙伴們鳍征。
首先黍翎,brew自帶的卸載MySQL命令:
brew remove mysql
刪除brew的安裝包目錄以及其他雜項:
# 我的MySQL是5.7版本,大家各自對號入座
sudo rm -rf /usr/local/Cellar/mysql@5.7
# 下面的無論哪個版本都可以執(zhí)行艳丛,如果沒有找到目錄就直接略過
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /tmp/mysql.*
sudo rm -rf /tmp/mysqlx.sock
sudo rm -rf /tmp/mysqlx.sock.lock
sudo rm -rf /usr/local/Library/Cache/Homebrew
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
清理
brew cleanup
brew uninstall mysql
安裝MySQL
# 依然使用brew安裝(自己作)
brew install mysql@5.7
下面分為兩種情況匣掸,請各位看官對號入座:
情況一:
# 如果出現(xiàn)這樣情況,那么就算安裝成功了氮双,可以直接跳過下一段碰酝,看配置了
? ~ brew postinstall mysql@5.7
==> Postinstalling mysql@5.7
==> /usr/local/Cellar/mysql@5.7/5.7.24/bin/mysqld --initialize-insecure --user=f
情況二:
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-30T06:25:31.095656Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2019-01-30T06:25:31.242178Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-01-30T06:25:31.266992Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-01-30T06:25:31.319878Z 0 [ERROR] unknown variable 'validate_password=off'
2019-01-30T06:25:31.319925Z 0 [ERROR] Aborting
# 如果出現(xiàn)這種情況,你需要進行以下配置
rm -rf /usr/local/var/mysql
# 這里插句話戴差,如果使用官方的dmg鏡像安裝的話送爸,用這條命令
rm -rf /usr/local/mysql
然后執(zhí)行:
brew postinstall mysql@5.7
大功告成!T焱臁碱璃!
配置:
# 這部分轉(zhuǎn)載的 http://www.reibang.com/p/c103776c014f
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):<–初次運行直接回車
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 是否設(shè)置root用戶密碼,輸入y并回車或直接回車
New password: <– 設(shè)置root用戶的密碼
Re-enter new password: <– 再輸入一次你設(shè)置的密碼
Password updated successfully!
Reloading privilege tables..
… Success!
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? [Y/n] <– 是否刪除匿名用戶,生產(chǎn)環(huán)境建議刪除饭入,所以直接回車
… 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? [Y/n] <–是否禁止root遠程登錄,根據(jù)自己的需求選擇Y/n并回車,建議禁止
… 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? [Y/n] <– 是否刪除test數(shù)據(jù)庫,直接回車
- 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? [Y/n] <– 是否重新加載權(quán)限表嵌器,直接回車
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!