在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)