数据库相关--在mac OX10.11.6上安装MySQL
一、之前失败情况
官网下载dmg文件安装、源码安装,下过5.6 5.7 8.0 版本,都可以安装成功,但是在电脑设置界面无法启动,每次点启动输入密码后,均闪一下绿色然后变红色,既然不能界面启动,那就使用终端试试,结果就是长时间的不停解决各种问题:不能连接到数据库的服务啦、找不到mysql.sock文件啦、PID错误啊等等等等,看过网上各种方式:kill已有mysql进程、新建/修改my.cnf文件、修改配置路径等等等等,数据库也是不断卸载、安装,均已失败告终。
二、完全卸载mysql
在安装之前,一定要完全卸载mysql,并删除相关的各种文件,依次运行以下语句:(如果不是root用户需要在前面加上sudo,也可使用sudo su -进行root)
mymac:~ root# rm -rf /usr/local/mysql* mymac:~ root# rm -rf /Library/StartupItems/MySQLCOM mymac:~ root# rm -rf /Library/PreferencePanes/My* mymac:~ root# rm -rf ~/Library/PreferencePanes/My* mymac:~ root# rm -rf /Library/Receipts/mysql* mymac:~ root# rm -rf /Library/Receipts/MySQL* mymac:~ root# rm -rf /var/db/receipts/com.mysql.*
三、使用brew安装
安装brew并更新:(可参考官网:https://brew.sh/)
mymac:~ root# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" mymac:~ root# brew update
安装mysql:
不能使用root用户安装,会报错:
mymac:~ mymac$ brew install mysql Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.22.el_capitan.bot Already downloaded: /Users/mymac/Library/Caches/Homebrew/mysql-5.7.22.el_capitan.bottle.tar.gz ==> Pouring mysql-5.7.22.el_capitan.bottle.tar.gz ==> 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 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 ==> Summary 🍺 /usr/local/Cellar/mysql/5.7.22: 317 files, 235MB
启动mysql服务:
mymac:~ mymac$ mysql.server start
Starting MySQL
SUCCESS!
启动mysql配置:
mymac:~ mymac$ 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: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 # 密码强度设置,最简单的输入0,中等输入1,复杂输入2 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y 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) : no ... 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. 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:
mymac:~ mymac$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 93 Server version: 5.7.22 Homebrew Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
问道,问道,道法自然,编程亦然。
作者:问道编程
浏览本文,如有些许收获,请点击推荐。
本站使用「署名 4.0 国际」创作共享协议,码字不易,如需转载或引用,需在文章明显位置注明作者及本文链接。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步