我刚刚在Mac OS x上安装了MySQL,下一步是设置root用户密码,所以我接下来这样做:
启动终端应用程序以访问Unix命令行。
在Unix提示符下,我执行了以下命令:
cd /usr/local/mysql/bin
./mysqladmin -u root password' password'
但是,当我执行命令时
./mysql -u root,这是答案:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 224
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
我不需要密码就能进入mysql命令行!
为什么会这样?
$ export PATH=$PATH:/usr/local/mysql/bin
now,to make this permanent:
$ echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bash_profile
next, start mysql in safe mode:
$ sudo mysqld_safe --skip-grant-tables;
If this does not work, go to System Preferences and stop MySQL server.
next, On the **other** terminal, you may use the below:
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE mysql.user SET authentication_string=null WHERE
User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
$ mysql -u root
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH
caching_sha2_password BY 'yourpassword';
$ mysql -u root -p
Enter password:
mysql> SELECT user();
next, start the mysql server in normal mode. and you're done with resetting your root password. this worked for mysql 8.0.17 ver. for me.
thanks to everyone on top, https://stackoverflow.com/questions/36099028/error-1064-42000-you-have-an-error-in-your-sql-syntax-want-to-configure-a-pa,
https://www.houseninetytwo.com/how-to-use-mysql-in-terminal-on-mac-os-high-sierra/: ~:文本=你% 5月20日% 20 % 20了% 20,% 2 fmysql % 2 fbin % 2 fmysql。= % 20应该% 20执行% 20 % 20对,返回% 20 % 20版本% % 20 mysql中的20个。
如果你忘记了MySQL的根密码,不记得或者想要闯入.....你可以在Linux或OS X的命令行中重置MySQL数据库密码,只要你知道你所在的机器的root用户密码:
(1)停止MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
(2)安全模式启动:
sudo mysqld_safe --skip-grant-tables
(3)这将是一个持续的命令,直到进程结束,所以打开另一个shell/终端窗口,登录没有密码:
mysql -u root
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
在上面的UPDATE命令中,只需将'password'替换为您自己的新密码,请确保保留引号
(4)节省和安静
FLUSH PRIVILEGES;
\q
启动MySQL
sudo /usr/local/mysql/support-files/mysql.server start
您可以手动关闭Mac上的MySQL,通过点击Apple菜单并打开系统首选项。选择“MySQL”首选项面板,然后点击“停止MySQL服务器”按钮停止Mac上的MySQL服务器。
停止MySQL后,需要执行以下步骤。
你需要在skip-grant-tables模式下启动MySQL
sudo /usr/local/mysql/support-files / mysql。服务器启动——skip-grant-tables
在您的终端中,输入此命令以刷新现有权限
/usr/local/mysql/bin/mysql
现在需要修改用户密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'
mysql >退出
然后,您可以转到Apple菜单并打开系统首选项。选择“MySQL”首选项面板,然后点击“停止MySQL服务器”按钮来停止Mac上的MySQL服务器。
最后,您可以再次进入Apple菜单并打开系统首选项。选择“MySQL”首选项面板,然后单击“启动MySQL服务器”按钮启动Mac上的MySQL服务器。