我刚刚在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命令行!

为什么会这样?


当前回答

这个解决方法在我的笔记本电脑上工作!

Mac与macOS v10.14.5 (Mojave)。

MySQL 8.0.17是用Homebrew安装的。

执行如下命令找到MySQL的路径 编译mysql信息 一旦路径已知,我运行这个: /usr/local/Cellar/mysql/8.0.17/bin/mysqld_safe——skip-grant-table 在另一个终端,我运行: Mysql -u root 在该终端中,我使用以下方法更改了root密码: 更新mysql。user='root'; 说完我就跑: 冲洗特权;

voilà,密码被重置。

参考文献

其他回答

停止mysqld服务器。

Mac OS X:系统首选项→MySQL→停止MySQL服务器 Linux(从终端):sudo systemctl停止mysqld.service

Start the server in safe mode with privilege bypass From Terminal: sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables In a new terminal window: sudo /usr/local/mysql/bin/mysql -u root This will open the MySQL command-line client. From here enter: UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES; quit Stop the mysqld server again and restart it in normal mode. Mac OS X (From Terminal): sudo /usr/local/mysql/support-files/mysql.server restart Linux Terminal: sudo systemctl restart mysqld

一旦你安装了MySQL,你需要建立“根”密码。如果您没有设置根密码,那么就没有根密码,您也不需要密码来登录。

因此,话虽如此,您需要建立一个根密码。

使用终端输入如下:

安装:设置root用户密码:

/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE

如果你犯了一个错误,或者需要修改root密码,请使用以下方法:

修改root密码:

cd /usr/local/mysql/bin/
./mysql -u root -p
> Enter password: [type old password invisibly]

use mysql;
update user set password=PASSWORD("NEW_PASSWORD_HERE") where User='root';
flush privileges;
quit

当我安装OS X v10.10 (Yosemite)时,MySQL出现了一个问题。我试了很多方法,但都没用。其实我找到了一个很简单的方法。试试这个。

首先以超级用户(su)权限登录到终端。 sudo苏 停止MySQL sudo /usr/local/mysql/support-files / mysql。服务器停止 安全模式启动: Sudo mysqld_safe——skip-grant-tables 打开另一台终端,以su权限登录,然后无需密码登录MySQL客户端(MySQL) Mysql -u root 修改密码 更新mysql。SET Password ('new_password') WHERE user ='root'; 冲洗的特权 冲洗特权; 现在你完成了。

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

Start your terminal and enter: sudo su Enter the password for you system Stop your MySQL server: sudo /usr/local/mysql/support-files/mysql.server stop Leave this window open, run second terminal window and enter here: mysql -u root And change your password for MySQL: UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root'; where "new_password" - your new password. You don't need old password for MySQL. Flush, quit and check your new password: FLUSH PRIVILEGES; Close all windows and check your new password for MySQL.