在 macOS 上安装 mysql
我正在尝试使用 Homebrew by brew install mysql 5.1.52
在 mac os 10.6 上设置 MySQL。
一切都很顺利,我也成功安装了 mysql_install_db
。
但是,当我尝试使用以下方式连接到服务器时:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root password 'mypass'
我得到:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'
我也尝试使用 -u root -proot 访问 mysqladmin 或 mysql,
但不管有没有密码,它都不起作用。
这是在全新机器上的全新安装,据我所知,新安装必须无需 root 密码即可访问。我也尝试过:
/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation
但我也得到
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
I'm trying to setup up MySQL on mac os 10.6 using Homebrew by brew install mysql 5.1.52
.
Everything goes well and I am also successful with the mysql_install_db
.
However when I try to connect to the server using:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root password 'mypass'
I get:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'
I've tried to access mysqladmin or mysql using -u root -proot
as well,
but it doesn't work with or without password.
This is a brand new installation on a brand new machine and as far as I know the new installation must be accessible without a root password. I also tried:
/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation
but I also get
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
我认为在已经安装了旧版本的 mysql 的情况下,人们最终可能会陷入这种境地。我遇到了同样的问题,并且上述解决方案都不适合我。我这样修复了它:
使用了brew的
remove
&cleanup
命令,卸载launchctl
脚本,然后删除/usr/local/var
中的mysql目录,删除我现有的/etc /my.cnf
(如果适用,请自行决定)和 launchctl plist更新了 plist 的字符串。另请注意,您的备用安全脚本目录将基于您正在安装的 MySQL 版本。
一步一步:
然后我从头开始:
brew install mysql
安装 mysql运行brew 建议的命令:(参见下面的注释)
使用
mysql.server start
命令启动mysql,以便能够登录它使用备用安全脚本:
遵循brew包脚本输出中的
launchctl
部分,例如,<前><代码>#start
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
#停止
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
注意:上的
--force
位brew cleanup
还将清理过时的小桶,认为这是一个新的自制功能。注意第二点:评论者表示不需要第 2 步。我不想测试它,所以 YMMV!
I think one can end up in this position with older versions of mysql already installed. I had the same problem and none of the above solutions worked for me. I fixed it thus:
Used brew's
remove
&cleanup
commands, unloaded thelaunchctl
script, then deleted the mysql directory in/usr/local/var
, deleted my existing/etc/my.cnf
(leave that one up to you, should it apply) and launchctl plistUpdated the string for the plist. Note also your alternate security script directory will be based on which version of MySQL you are installing.
Step-by-step:
I then started from scratch:
brew install mysql
ran the commands brew suggested: (see note: below)
Start mysql with
mysql.server start
command, to be able to log on itUsed the alternate security script:
Followed the
launchctl
section from the brew package script output such as,Note: the
--force
bit onbrew cleanup
will also cleanup outdated kegs, think it's a new-ish homebrew feature.Note the second: a commenter says step 2 is not required. I don't want to test it, so YMMV!
以下是详细说明,结合从 Mac 上删除所有 MySQL,然后安装 Sedorner 上面所写的 Brew Way:
按照 技术实验室
ps -ax | grep mysql
杀死
任何 MySQL 进程sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql< /code>
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
code>/etc/hostconfig
并删除行MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/ *mysql*
sudo rm -rf /tmp/mysql*
mysql
,它不应该工作Brew install MySQL per user Sedorner from this StackOverflow 回答
brew doctor
并修复所有错误brew remove mysql
brew 清理
brew 更新
brew安装mysql
取消设置 TMPDIR
mysql.server启动
运行 Brew 建议的命令,将 MySQL 添加到
launchctl
以便它在启动时自动启动mysql
现在应该可以正常工作,并按预期 Godspeed 一直运行。
Here are detailed instructions combining getting rid of all MySQL from your Mac then installing it The Brew Way as Sedorner wrote above:
Remove MySQL completely per The Tech Lab
ps -ax | grep mysql
kill
any MySQL processessudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
/etc/hostconfig
and remove the lineMYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
sudo rm -rf /tmp/mysql*
mysql
, it shouldn't workBrew install MySQL per user Sedorner from this StackOverflow answer
brew doctor
and fix any errorsbrew remove mysql
brew cleanup
brew update
brew install mysql
unset TMPDIR
mysql.server start
run the commands Brew suggests, add MySQL to
launchctl
so it automatically launches at startupmysql
should now work and be running all the time as expectedGodspeed.
有同样的问题。似乎设置说明或正在创建的初始表有问题。这就是我在我的机器上运行 mysqld 的方法。
如果 mysqld 服务器已经在您的 Mac 上运行,请首先使用
以下命令停止它:launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
使用以下命令启动 mysqld 服务器:任何人以完全权限登录。
mysqld_safe --skip-grant-tables
然后运行
mysql -u root
现在应该可以让您在没有密码的情况下成功登录。以下命令应重置所有 root 密码。UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;
现在,如果您终止正在运行的 mysqld_safe 副本并在不使用skip-grant-tables 选项的情况下再次启动它,您应该能够使用
mysql -u root -p
登录> 和您刚刚设置的新密码。Had the same problem. Seems like there is something wrong with the set up instructions or the initial tables that are being created. This is how I got mysqld running on my machine.
If the mysqld server is already running on your Mac, stop it first with:
launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
Start the mysqld server with the following command which lets anyone log in with full permissions.
mysqld_safe --skip-grant-tables
Then run
mysql -u root
which should now let you log in successfully without a password. The following command should reset all the root passwords.UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;
Now if you kill the running copy of mysqld_safe and start it up again without the skip-grant-tables option, you should be able to log in with
mysql -u root -p
and the new password you just set.Homebrew
brew doctor
并解决 homebrew 希望您修复的任何问题brew install mysql
brew services restart mysql
mysql.server start
mysql_secure_installation
Homebrew
brew doctor
and address anything homebrew wants you to fixbrew install mysql
brew services restart mysql
mysql.server start
mysql_secure_installation
如果brew安装了MySQL 5.7,则该过程与以前的版本略有不同。
要重置 root 密码,请执行以下操作:
临时密码将打印到控制台,并且只能用于更新 root 密码:
If brew installed MySQL 5.7, the process is a bit different than for previous versions.
In order to reset the root password, proceed as follows:
A temporary password will be printed to the console and it can only be used for updating the root password:
好吧,我有同样的问题并解决了。由于某种原因,当使用 Homebrew 安装 mysql 时,mysql_secure_installation 脚本不能开箱即用,所以我手动完成了。 在 CLI 上输入:
这应该会让您进入 mysql。现在执行以下操作(取自 mysql_secure_installation):
现在退出并返回 mysql:
mysql -u root -p
Okay I had the same issue and solved it. For some reason the mysql_secure_installation script doesn't work out of the box when using Homebrew to install mysql, so I did it manually. On the CLI enter:
That should get you into mysql. Now do the following (taken from mysql_secure_installation):
Now exit and get back into mysql with:
mysql -u root -p
我刚才也遇到了同样的问题。如果你
brew info mysql
并按照步骤操作,如果我没记错的话,root密码应该是new-password
。我看到的和你看到的一样。 这篇文章对我帮助最大。结果我没有为我创建任何帐户。当我运行 mysqld_safe 后登录并执行
select * from user;
时,没有返回任何行。我打开了 MySQLWorkbench,并运行了 mysqld_safe,并添加了一个具有我期望的所有权限的 root 帐户。现在这对我来说效果很好。I had the same problem just now. If you
brew info mysql
and follow the steps it looks like the root password should benew-password
if I remember correctly. I was seeing the same thing you are seeing. This article helped me the most.It turned out I didn't have any accounts created for me. When I logged in after running
mysqld_safe
and didselect * from user;
no rows were returned. I opened the MySQLWorkbench with themysqld_safe
running and added aroot
account with all the privs I expected. This are working well for me now.如果 mysql 已经安装,
请完全停止 mysql。
mysql.server stop
<-- 可能需要根据您的版本进行编辑ps -ef | grep mysql
<-- 列出名称中带有 mysql 的进程kill [PID]
<-- 通过 PID 杀死进程删除文件。上面的说明很好。我将添加:
sudo find /。 -name "*mysql*"
rm -rf
这些文件。请注意,许多程序都有您不想删除的 mysql 驱动程序。例如,不要删除 PHP 安装目录中的内容。请删除其自己的 mysql 目录中的内容。安装
希望你有自制软件。如果没有,请下载。
我喜欢以root身份运行brew,但我认为你不必这样做。编辑2018:你不能再以root身份运行brew
sudobrewupdate
sudobrewinstallcmake
<--mysql的依赖,有用sudobrewinstallopenssl< /code> <-- mysql 的依赖关系,很有用
sudo brew info mysql
<-- 浏览一下这个...它可以让您了解接下来会发生什么sudo brew install mysql - - 嵌入; say done
<-- 使用嵌入式服务器安装 mysql。告诉你它何时完成(我的安装花了 10 分钟)然后
sudo chown -R mysql /usr/local/var/mysql/
<-- mysql 不会为我工作,直到我运行这个命令sudo mysql.server start
<-- 确切的语法可能会有所不同If mysql is already installed
Stop mysql completely.
mysql.server stop
<-- may need editing based on your versionps -ef | grep mysql
<-- lists processes with mysql in their namekill [PID]
<-- kill the processes by PIDRemove files. Instructions above are good. I'll add:
sudo find /. -name "*mysql*"
rm -rf
these files. Note that many programs have drivers for mysql which you do not want to remove. For example, don't delete stuff in a PHP install's directory. Do remove stuff in its own mysql directory.Install
Hopefully you have homebrew. If not, download it.
I like to run brew as root, but I don't think you have to. Edit 2018: you can't run brew as root anymore
sudo brew update
sudo brew install cmake
<-- dependency for mysql, usefulsudo brew install openssl
<-- dependency for mysql, usefulsudo brew info mysql
<-- skim through this... it gives you some idea of what's coming nextsudo brew install mysql --with-embedded; say done
<-- Installs mysql with the embedded server. Tells you when it finishes (my install took 10 minutes)Afterwards
sudo chown -R mysql /usr/local/var/mysql/
<-- mysql wouldn't work for me until I ran this commandsudo mysql.server start
<-- once again, the exact syntax may varyTL;DR
使用 Brew 安装后,MySQL 服务器可能无法运行。如果您不希望 MySQL 作为后台服务运行,请尝试
brew services start mysql
或只是mysql.server start
。完整故事:
我刚刚在运行 Sierra 的新 MacBook Pro 上安装了 MySQL(稳定版)5.7.17,并且在运行
mysql_secure_installation
时也遇到了错误:说什么?< /em>
根据 Brew 的安装信息,
mysql_secure_installation
应该提示我...保护安装。我认为 MySQL 服务器可能没有运行,而且确实如此。运行brew services start mysql
,然后mysql_secure_installation
工作得非常顺利。TL;DR
MySQL server might not be running after installation with Brew. Try
brew services start mysql
or justmysql.server start
if you don't want MySQL to run as a background service.Full Story:
I just installed MySQL (stable) 5.7.17 on a new MacBook Pro running Sierra and also got an error when running
mysql_secure_installation
:Say what?
According to the installation info from Brew,
mysql_secure_installation
should prompt me to... secure the installation. I figured the MySQL server might not be running and rightly so. Runningbrew services start mysql
and thenmysql_secure_installation
worked like a charm.这是 MySQL 5.7 的更新
Here is an update for MySQL 5.7
只是为了在以前的答案中添加一些内容 - 当从 MySql 5.6 升级到 MySql 8.0 时,我按照此处提供的步骤进行了彻底卸载,但出现了以下错误 我
花了一些时间才弄清楚。在这里找到了线索:
https://discourse.brew.sh/t/clean-removal- of-mysql/2251
所以,我的问题的关键是卸载后删除 /usr/local/etc/my.cnf 文件。
最后一步之后,MySql 终于开始工作了。
Just to add something to previous answers - When upgrading from MySql 5.6 to MySql 8.0, I followed the steps provided here to make a clean uninstall, yet I got following errors
Took me some time to figure it out. Found a clue here:
https://discourse.brew.sh/t/clean-removal-of-mysql/2251
So, the key to my problem was removing /usr/local/etc/my.cnf file after uninstall.
After that one last step, MySql finally started working.
尝试给予 mysql 的授予权限命令
Try by giving Grant permission Command of mysql
我尝试重新启动 mysql 后遇到了同样的问题。
为了方便起见,我在 .profile 中使用以下两个别名
在停止 mysql 然后尝试重新启动后,我遇到了您遇到的问题。我查看了 launchctl load,它报告了“没有找到可加载的内容”错误。
经过快速搜索后,我发现了这个..
http://www.daveoncode.com/2013/02/01/solve-mac-osx-launchctl-nothing-found-to-load-error/
所以我更新了我
mysql-start
别名如下这解决了我的问题,可能对您有用。
I had the same issue after I tried to restart mysql.
I use the following two aliases in my .profile for convenience
After stoping mysql and then trying to restart I experienced the issue you were having. I looked into the launchctl load and it was reporting a “nothing found to load” error.
After a quick search I found this..
http://www.daveoncode.com/2013/02/01/solve-mac-osx-launchctl-nothing-found-to-load-error/
So I updated me
mysql-start
alias as followsThis solved my issue which may be useful for you.
当将brew与最新版本的mysql和yosemite一起使用时,上述答案(或我在其他地方看到的几十个答案中的任何一个)都不适合我。我最终通过brew安装了不同的mysql版本。
通过说(例如)
为我工作来指定旧版本。希望这对某人有帮助。这是一个令人沮丧的问题,我觉得我永远被困在这个问题上。
None of the above answers (or any of the dozens of answers I saw elsewhere) worked for me when using brew with the most recent version of mysql and yosemite. I ended up installing a different mysql version via brew.
Specifying an older version by saying (for example)
Worked for me. Hope this helps someone. This was a frustrating problem that I felt like I was stuck on forever.
Mysql 的“基本路径”存储在
/etc/my.cnf
中,当您进行 brew 升级时,该路径不会更新。只需打开它并更改 basedir 值例如,更改此:
以指向新版本:
使用以下命令重新启动 mysql:
The "Base-Path" for Mysql is stored in
/etc/my.cnf
which is not updated when you do brew upgrade. Just open it and change the basedir valueFor example, change this:
to point to the new version:
Restart mysql with:
尝试我为 MariaDB 提供的解决方案,它也适用于 MySQL 的高变化:
MacOSX homebrew mysql root 密码
总之,尝试用你的用户名登录!不是根。
尝试使用与您的 MacOS 帐户用户名相同的名称,例如 johnsmit。
要以 root 身份登录,请发出:
Try solution I provided for MariaDB, high change that it works with MySQL also:
MacOSX homebrew mysql root password
In short, try to login with your username! not root.
Try same name as your MacOS account username, e.g. johnsmit.
To login as root, issue:
删除
/opt/homebrew/var/mysql
就可以了。显然存在 mysql 数据(包括密码),因此上述所有操作均无效。deleting
/opt/homebrew/var/mysql
did the job. Apparently there were mysql data (including password) so all this manipulations described above were to no avail.