在 macOS 上 brew install mysql

brew install mysql on macOS(在 macOS 上 brew install mysql)
本文介绍了在 macOS 上 brew install mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试通过 brew install mysql 5.1.52 使用 Homebrew 在 mac os 10.6 上设置 MySQL.

一切顺利,我也成功使用 mysql_install_db.
但是,当我尝试使用以下方法连接到服务器时:

/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root 密码 'mypass'

我明白了:

<前>/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin:连接到'localhost'的服务器失败的错误:'拒绝用户'root'@'localhost'的访问(使用密码:NO)'

我也尝试使用 -u root -proot 访问 mysqladmin 或 mysql,
但无论有没有密码它都不起作用.

这是在全新机器上的全新安装,据我所知,新安装必须无需 root 密码即可访问.我也试过:

/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation

但我也得到

<前>错误 1045 (28000):用户 'root'@'localhost' 访问被拒绝(使用密码:NO)

解决方案

我认为如果已经安装了旧版本的 mysql,你可能会处于这个位置.我遇到了同样的问题,上述解决方案都不适合我.我是这样修复的:

使用 brew 的 remove &cleanup命令,卸载launchctl脚本,然后删除/usr/local/var中的mysql目录,删除我现有的/etc/my.cnf (如果适用,则由您决定)和 launchctl plist

更新了 plist 的字符串.另请注意,您的备用安全脚本目录将基于您正在安装的 MySQL 版本.

分步说明:

brew 删除 mysql酿造清理launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plistrm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist须藤 rm -rf/usr/local/var/mysql

然后我从头开始:

  1. brew install mysql
  2. 安装 mysql
  3. 运行 brew 建议的命令:(见注释:下面)

    取消设置 TMPDIRmysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

  4. mysql.server start命令启动mysql,以便能够登录

  5. 使用备用安全脚本:

    /usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation

  6. 遵循 brew 包脚本输出中的 launchctl 部分,例如,

    #startlaunchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist#停止launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

注意:brew cleanup 上的 --force 位也将清理过时的小桶,认为这是一个新的自制功能.

注意第二点:评论者说第 2 步不是必需的.我不想测试它,所以 YMMV!

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)

解决方案

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 the launchctl 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 plist

Updated 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:

brew remove mysql

brew cleanup

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

sudo rm -rf /usr/local/var/mysql

I then started from scratch:

  1. installed mysql with brew install mysql
  2. ran the commands brew suggested: (see note: below)

    unset TMPDIR
    
    mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
    

  3. Start mysql with mysql.server start command, to be able to log on it

  4. Used the alternate security script:

    /usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation
    

  5. Followed the launchctl section from the brew package script output such as,

    #start
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    
    #stop
    launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    

Note: the --force bit on brew 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!

这篇关于在 macOS 上 brew install mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)