我正在尝试在mac os 10.6上使用Homebrew by brew安装MySQL 5.1.52。
一切都很顺利,我也成功地使用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)'
我尝试访问mysqladmin或mysql使用-u root - root以及,
但是有没有密码都不行。
这是全新机器上的全新安装,据我所知,新安装必须在没有根密码的情况下访问。我还试过:
/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation
但我也得到了
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
好吧,我也遇到过同样的问题,但我已经解决了。由于某种原因,mysql_secure_installation脚本在使用Homebrew安装mysql时不能开箱即用,所以我手动安装了。在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
我也有同样的问题。似乎设置指令或正在创建的初始表有问题。这就是我在我的机器上运行mysqld的方式。
如果mysqld服务器已经在你的Mac上运行,首先用以下命令停止它:
启动ctl卸载-w ~/图书馆/LaunchAgents/com.mysql mysqld.plist
使用以下命令启动mysqld服务器,允许任何人以完全权限登录。
mysqld_safe——skip-grant-tables
然后运行mysql -u root,现在应该可以让你成功登录,无需密码。下面的命令应该重置所有的root密码。
更新mysql。SET Password ('NewPassword') WHERE user ='root';冲洗特权;
现在,如果你关闭了mysqld_safe的运行副本,并在没有skip-grant-tables选项的情况下重新启动它,你应该可以使用mysql -u root -p和你刚刚设置的新密码登录。
只是在之前的回答中添加一些东西-当从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终于开始工作了。
下面是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 mysql@5.7
brew cleanup
mv /usr/local/var/mysql /usr/local/var/mysql.bak
brew install mysql@5.7
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!