在 macOS 上安装 mysql

发布于 2024-10-06 10:37:02 字数 777 浏览 10 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

夏日浅笑〃 2024-10-13 10:37:02

我认为在已经安装了旧版本的 mysql 的情况下,人们最终可能会陷入这种境地。我遇到了同样的问题,并且上述解决方案都不适合我。我这样修复了它:

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

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

一步一步:

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

然后我从头开始:

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

    取消设置 TMPDIR
    
    mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
    
  3. 使用mysql.server start命令启动mysql,以便能够登录它

  4. 使用备用安全脚本:

    <代码>/usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation
    
  5. 遵循brew包脚本输出中的launchctl部分,例如,

    <前><代码>#start
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

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

注意:上的--forcebrew 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 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!

青朷 2024-10-13 10:37:02

以下是详细说明,结合从 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_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp # whoami 是内联执行的
    
  • 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
  • stop and kill any MySQL processes
  • sudo 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
  • edit /etc/hostconfig and remove the line 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*
  • try to run mysql, it shouldn't work

Brew install MySQL per user Sedorner from this StackOverflow answer

  • brew doctor and fix any errors

  • brew remove mysql

  • brew cleanup

  • brew update

  • brew install mysql

  • unset TMPDIR

      mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp # whoami is executed inline
    
  • mysql.server start

  • run the commands Brew suggests, add MySQL to launchctl so it automatically launches at startup

mysql should now work and be running all the time as expected

Godspeed.

落墨 2024-10-13 10:37:02

有同样的问题。似乎设置说明或正在创建的初始表有问题。这就是我在我的机器上运行 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.

白芷 2024-10-13 10:37:02

Homebrew

  1. 首先,确保安装了 homebrew
  2. 运行 brew doctor 并解决 homebrew 希望您修复的任何问题
  3. 运行 brew install mysql
  4. 运行 brew services restart mysql
  5. 运行mysql.server start
  6. 运行mysql_secure_installation

Homebrew

  1. First, make sure you have homebrew installed
  2. Run brew doctor and address anything homebrew wants you to fix
  3. Run brew install mysql
  4. Run brew services restart mysql
  5. Run mysql.server start
  6. Run mysql_secure_installation
转身以后 2024-10-13 10:37:02

如果brew安装了MySQL 5.7,则该过程与以前的版本略有不同。
要重置 root 密码,请执行以下操作:

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

临时密码将打印到控制台,并且只能用于更新 root 密码:

mysql.server start
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'my-new-password';" | mysql -uroot --password=TEMPORARY_PASSWORD

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:

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

A temporary password will be printed to the console and it can only be used for updating the root password:

mysql.server start
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'my-new-password';" | mysql -uroot --password=TEMPORARY_PASSWORD
如果没有你 2024-10-13 10:37:02

好吧,我有同样的问题并解决了。由于某种原因,当使用 Homebrew 安装 mysql 时,mysql_secure_installation 脚本不能开箱即用,所以我手动完成了。 在 CLI 上输入

mysql -u root

这应该会让您进入 mysql。现在执行以下操作(取自 mysql_secure_installation):

UPDATE mysql.user SET Password=PASSWORD('your_new_pass') WHERE User='root';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
DROP DATABASE test;
FLUSH PRIVILEGES;

现在退出并返回 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:

mysql -u root

That should get you into mysql. Now do the following (taken from mysql_secure_installation):

UPDATE mysql.user SET Password=PASSWORD('your_new_pass') WHERE User='root';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
DROP DATABASE test;
FLUSH PRIVILEGES;

Now exit and get back into mysql with: mysql -u root -p

微凉 2024-10-13 10:37:02

我刚才也遇到了同样的问题。如果你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 be new-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 did select * from user; no rows were returned. I opened the MySQLWorkbench with the mysqld_safe running and added a root account with all the privs I expected. This are working well for me now.

千柳 2024-10-13 10:37:02

如果 mysql 已经安装,

请完全停止 mysql。

  1. mysql.server stop <-- 可能需要根据您的版本进行编辑
  2. ps -ef | grep mysql <-- 列出名称中带有 mysql 的进程
  3. kill [PID] <-- 通过 PID 杀死进程

删除文件。上面的说明很好。我将添加:

  1. sudo find /。 -name "*mysql*"
  2. 根据您的判断,rm -rf 这些文件。请注意,许多程序都有您不想删除的 mysql 驱动程序。例如,不要删除 PHP 安装目录中的内容。请删除其自己的 mysql 目录中的内容。

安装

希望你有自制软件。如果没有,请下载。

我喜欢以root身份运行brew,但我认为你不必这样做。编辑2018:你不能再以root身份运行brew

  1. sudobrewupdate
  2. sudobrewinstallcmake<--mysql的依赖,有用
  3. sudobrewinstallopenssl< /code> <-- mysql 的依赖关系,很有用
  4. sudo brew info mysql <-- 浏览一下这个...它可以让您了解接下来会发生什么
  5. sudo brew install mysql - - 嵌入; say done <-- 使用嵌入式服务器安装 mysql。告诉你它何时完成(我的安装花了 10 分钟)

然后

  1. sudo chown -R mysql /usr/local/var/mysql/ <-- mysql 不会为我工作,直到我运行这个命令
  2. sudo mysql.server start <-- 确切的语法可能会有所不同
  3. 在 mysql 中创建用户 (http://dev.mysql.com/doc/refman/5.7/en/create-user.html)。请记住为 root 用户添加密码。

If mysql is already installed

Stop mysql completely.

  1. mysql.server stop <-- may need editing based on your version
  2. ps -ef | grep mysql <-- lists processes with mysql in their name
  3. kill [PID] <-- kill the processes by PID

Remove files. Instructions above are good. I'll add:

  1. sudo find /. -name "*mysql*"
  2. Using your judgement, 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

  1. sudo brew update
  2. sudo brew install cmake <-- dependency for mysql, useful
  3. sudo brew install openssl <-- dependency for mysql, useful
  4. sudo brew info mysql <-- skim through this... it gives you some idea of what's coming next
  5. sudo brew install mysql --with-embedded; say done <-- Installs mysql with the embedded server. Tells you when it finishes (my install took 10 minutes)

Afterwards

  1. sudo chown -R mysql /usr/local/var/mysql/ <-- mysql wouldn't work for me until I ran this command
  2. sudo mysql.server start <-- once again, the exact syntax may vary
  3. Create users in mysql (http://dev.mysql.com/doc/refman/5.7/en/create-user.html). Remember to add a password for the root user.
醉城メ夜风 2024-10-13 10:37:02

TL;DR

使用 Brew 安装后,MySQL 服务器可能无法运行。如果您不希望 MySQL 作为后台服务运行,请尝试 brew services start mysql 或只是 mysql.server start

完整故事

我刚刚在运行 Sierra 的新 MacBook Pro 上安装了 MySQL(稳定版)5.7.17,并且在运行 mysql_secure_installation 时也遇到了错误:

Securing the MySQL server deployment.

Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

说什么?< /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 just mysql.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:

Securing the MySQL server deployment.

Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

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. Running brew services start mysql and then mysql_secure_installation worked like a charm.

风追烟花雨 2024-10-13 10:37:02

这是 MySQL 5.7 的更新

bash --version
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin17.0.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

#========================================
brew --version
Homebrew 1.7.6
Homebrew/homebrew-core (git revision eeb08; last commit 2018-09-27)
Homebrew/homebrew-cask (git revision c9f62; last commit 2018-09-27)

#========================================
mysql --version
mysql  Ver 14.14 Distrib 5.7.23, for osx10.13 (x86_64) using  EditLine wrapper

#========================================
system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: macOS 10.13.3 (17D47)
      Kernel Version: Darwin 17.4.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: EdisonMacHomeBj
      User Name: Edison (edison)
      Secure Virtual Memory: Enabled
      System Integrity Protection: Disabled
      Time since boot: 6 days 23:13
brew remove [email protected]
brew cleanup
mv /usr/local/var/mysql /usr/local/var/mysql.bak
brew install [email protected]
rm -rf /usr/local/var/mysql

#========================================
mysqld --initialize
2018-09-28T04:54:06.526061Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-28T04:54:06.542625Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2018-09-28T04:54:07.096637Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-28T04:54:07.132950Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-28T04:54:07.196824Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 87cf2f10-c2da-11e8-ac2d-ba163df10130.
2018-09-28T04:54:07.224871Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-28T04:54:07.366688Z 0 [Warning] CA certificate ca.pem is self signed.
2018-09-28T04:54:07.457954Z 1 [Note] A temporary password is generated for root@localhost: kq3K=JR8;GqZ

#========================================
mysql_secure_installation -uroot -p"kq3K=JR8;GqZ"
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

Securing the MySQL server deployment.


The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new 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: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:
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) : n

 ... 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) : n

 ... skipping.
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!

Here is an update for MySQL 5.7

bash --version
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin17.0.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

#========================================
brew --version
Homebrew 1.7.6
Homebrew/homebrew-core (git revision eeb08; last commit 2018-09-27)
Homebrew/homebrew-cask (git revision c9f62; last commit 2018-09-27)

#========================================
mysql --version
mysql  Ver 14.14 Distrib 5.7.23, for osx10.13 (x86_64) using  EditLine wrapper

#========================================
system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: macOS 10.13.3 (17D47)
      Kernel Version: Darwin 17.4.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: EdisonMacHomeBj
      User Name: Edison (edison)
      Secure Virtual Memory: Enabled
      System Integrity Protection: Disabled
      Time since boot: 6 days 23:13
brew remove [email protected]
brew cleanup
mv /usr/local/var/mysql /usr/local/var/mysql.bak
brew install [email protected]
rm -rf /usr/local/var/mysql

#========================================
mysqld --initialize
2018-09-28T04:54:06.526061Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-09-28T04:54:06.542625Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2018-09-28T04:54:07.096637Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-09-28T04:54:07.132950Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-09-28T04:54:07.196824Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 87cf2f10-c2da-11e8-ac2d-ba163df10130.
2018-09-28T04:54:07.224871Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-09-28T04:54:07.366688Z 0 [Warning] CA certificate ca.pem is self signed.
2018-09-28T04:54:07.457954Z 1 [Note] A temporary password is generated for root@localhost: kq3K=JR8;GqZ

#========================================
mysql_secure_installation -uroot -p"kq3K=JR8;GqZ"
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

Securing the MySQL server deployment.


The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new 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: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:
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) : n

 ... 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) : n

 ... skipping.
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!
请你别敷衍 2024-10-13 10:37:02

只是为了在以前的答案中添加一些内容 - 当从 MySql 5.6 升级到 MySql 8.0 时,我按照此处提供的步骤进行了彻底卸载,但出现了以下错误 我

2019-11-05T07:57:31.359304Z 0 [ERROR] [MY-000077] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld: Error while setting value 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2019-11-05T07:57:31.359330Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/var/mysql is unusable. You can remove all files that the server added to it.
2019-11-05T07:57:31.359413Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-11-05T07:57:31.359514Z 0 [Note] [MY-010120] [Server] Binlog end

花了一些时间才弄清楚。在这里找到了线索:
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

2019-11-05T07:57:31.359304Z 0 [ERROR] [MY-000077] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld: Error while setting value 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2019-11-05T07:57:31.359330Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/var/mysql is unusable. You can remove all files that the server added to it.
2019-11-05T07:57:31.359413Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-11-05T07:57:31.359514Z 0 [Note] [MY-010120] [Server] Binlog end

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.

绅刃 2024-10-13 10:37:02

尝试给予 mysql 的授予权限命令

Try by giving Grant permission Command of mysql

酒绊 2024-10-13 10:37:02

我尝试重新启动 mysql 后遇到了同样的问题。

为了方便起见,我在 .profile 中使用以下两个别名

alias mysql-stop='launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'
alias mysql-start='launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist' 

在停止 mysql 然后尝试重新启动后,我遇到了您遇到的问题。我查看了 launchctl load,它报告了“没有找到可加载的内容”错误。

经过快速搜索后,我发现了这个..

http://www.daveoncode.com/2013/02/01/solve-mac-osx-launchctl-nothing-found-to-load-error/

所以我更新了我 mysql-start 别名如下

alias mysql-start='launchctl load -w -F ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'

这解决了我的问题,可能对您有用。

I had the same issue after I tried to restart mysql.

I use the following two aliases in my .profile for convenience

alias mysql-stop='launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'
alias mysql-start='launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist' 

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 follows

alias mysql-start='launchctl load -w -F ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'

This solved my issue which may be useful for you.

人间不值得 2024-10-13 10:37:02

当将brew与最新版本的mysql和yosemite一起使用时,上述答案(或我在其他地方看到的几十个答案中的任何一个)都不适合我。我最终通过brew安装了不同的mysql版本。

通过说(例如)

brew install mysql56

为我工作来指定旧版本。希望这对某人有帮助。这是一个令人沮丧的问题,我觉得我永远被困在这个问题上。

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)

brew install mysql56

Worked for me. Hope this helps someone. This was a frustrating problem that I felt like I was stuck on forever.

弥繁 2024-10-13 10:37:02

Mysql 的“基本路径”存储在 /etc/my.cnf 中,当您进行 brew 升级时,该路径不会更新。只需打开它并更改 basedir 值

例如,更改此:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.13

以指向新版本:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.19

使用以下命令重新启动 mysql:

mysql.server start

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 value

For example, change this:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.13

to point to the new version:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.19

Restart mysql with:

mysql.server start
安穩 2024-10-13 10:37:02

尝试我为 MariaDB 提供的解决方案,它也适用于 MySQL 的高变化:

MacOSX homebrew mysql root 密码

总之,尝试用你的用户名登录!不是根。

尝试使用与您的 MacOS 帐户用户名相同的名称,例如 johnsmit。

要以 root 身份登录,请发出:

mysql -u johnsmit

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:

mysql -u johnsmit
宣告ˉ结束 2024-10-13 10:37:02

删除 /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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文