I just installed MySQL on Mac OS X. The next step was setting the root user password, so I did this next:
我刚在Mac OS x上安装了MySQL,下一步是设置根用户密码,接下来我做了如下操作:
- Launch the terminal app to access the Unix command line.
- 启动终端应用程序以访问Unix命令行。
-
Under the Unix prompt I executed these commands:
在Unix提示下,我执行以下命令:
$ cd /usr/local/mysql/bin $ ./mysqladmin -u root password 'password'
But, when I execute the command
但是,当我执行命令时。
$ ./mysql -u root
, this is the answer:
$ ./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>
I can get into the mysql
command line without any password!
我可以进入mysql命令行,没有任何密码!
Why is this?
这是为什么呢?
12 个解决方案
#1
279
Try the command FLUSH PRIVILEGES
when you log into the MySQL terminal. If that doesn't work, try the following set of commands while in the MySQL terminal
当您登录到MySQL终端时,尝试使用命令刷新特权。如果这不起作用,请在MySQL终端中尝试以下命令集。
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Change out NEWPASSWORD with whatever password you want. Should be all set!
用你想要的密码修改新密码。应该都准备好了!
Update: As of MySQL 5.7, the password
field has been renamed authentication_string
. When changing the password, use the following query to change the password. All other commands remain the same:
更新:在MySQL 5.7中,密码字段被重命名为authentication_string。在更改密码时,使用以下查询更改密码。所有其他命令保持不变:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
#2
166
If you don't remember the password you set for root and need to reset it, follow these steps:
如果您不记得为root设置的密码,需要重置它,请按照以下步骤操作:
- Stop the mysqld server, this varies per install
- 停止mysqld服务器,每个安装都不同。
- Run the server in safe mode with privilege bypass
- 使用权限绕过的安全模式运行服务器。
sudo mysqld_safe --skip-grant-tables;
sudo mysqld_safe——skip-grant-tables;
- In a new window connect to the database, set a new password and flush the permissions & quit:
- 在一个新窗口连接到数据库,设置一个新密码并刷新权限&退出:
mysql -u root
mysql - u根
For MySQL older than MySQL 5.7 use:
对于MySQL超过MySQL 5.7的使用:
UPDATE mysql.user SET Password=PASSWORD('your-password') WHERE User='root';
更新mysql。用户设置密码=密码('your-password'),用户='root';
For MySQL 5.7+ use:
MySQL 5.7 +使用:
USE mysql;
使用mysql;
UPDATE mysql.user SET authentication_string=PASSWORD("your-password") WHERE User='root';
更新mysql。用户设置authentication_string=PASSWORD(“your-password”),其中user ='root';
Refresh and quit:
刷新和退出:
FLUSH PRIVILEGES;
冲洗特权;
\q
\问
- Stop the safe mode server and start your regular server back. The new password should work now. Worked like a charm for me :)
- 停止安全模式服务器并启动您的常规服务器。新密码现在应该可以使用了。对我来说是一种魅力
#3
82
Once you've installed MySQL, you'll need to establish the "root" password. If you don't establish a root password, then, well, there is no root password, and you don't need a password to log in.
一旦安装了MySQL,就需要建立“根”密码。如果您没有建立根密码,那么,没有根密码,您不需要密码登录。
So, that being said, you need to establish a root password.
因此,您需要建立一个根密码。
Using terminal enter the following:
使用终端输入如下:
Installation: Set root user password:
/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE
If you've made a mistake, or need to change the root password use the following:
如果您犯了错误,或者需要更改根密码,请使用以下内容:
Change root password:
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
#4
31
The instructions provided in the mysql website is so clear, than the above mentioned
mysql网站提供的说明非常清晰,比上面提到的要清楚。
1. sudo /usr/local/mysql/support-files/mysql.server stop
2) sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
3) /usr/local/mysql/support-files/mysql
4) mysql> FLUSH PRIVILEGES;
5) mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
6) Ctrl + z
7) sudo /usr/local/mysql/support-files/mysql.server start
8) /usr/local/mysql/support-files/mysql -u root -p
9) enter the new password i.e MyNewPass
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
#5
19
-
Stop the mysqld server. Typically this can be done from 'System Prefrences' > MySQL > 'Stop MySQL Server'
停止mysqld服务器。一般来说,这可以从> MySQL > 'Stop MySQL服务器'中完成
-
Start the server in safe mode with privilege bypass From a terminal:
以安全模式启动服务器,特权绕过终端:
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
sudo /usr/local/mysql/bin/mysqld_safe——skip-grant-tables
-
In a new terminal window:
在一个新的终端窗口:
sudo /usr/local/mysql/bin/mysql -u root
sudo /usr/local/mysql/bin/mysql - u根
UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root';
更新mysql。用户设置authentication_string=PASSWORD('NewPassword'),用户='root';
FLUSH PRIVILEGES;
冲洗特权;
\q
\问
-
Stop the mysqld server again and restart it in normal mode.
再次停止mysqld服务器并在正常模式下重新启动它。
#6
15
In the terminal, write mysql -u root -p
and hit Return. Enter the current mysql password that you must have noted down. And set the password SET PASSWORD = PASSWORD('new_password');
在终端中,编写mysql -u root -pand点击返回。输入您必须记下的当前mysql密码。设置密码设置密码=密码('new_password');
Please refer to this documentation here for more details.
更多细节请参考这里的文档。
#7
13
For new Mysql 5.7 for some reason bin commands of Mysql not attached to the shell:
对于新的Mysql 5.7,由于某些原因,Mysql的bin命令没有附加到shell中:
-
Restart the Mac after install.
安装后重新启动Mac。
-
Start Mysql:
Mysql开始:
System Preferences > Mysql > Start button
系统首选> Mysql >启动按钮。
-
Go to Mysql install folder in terminal:
到终端的Mysql安装文件夹:
$ cd /usr/local/mysql/bin/
$ cd /usr/local/mysql/bin/
-
Access to Mysql:
对Mysql的访问:
$ ./mysql -u root -p
$ ./mysql -u root -p。
and enter the initial password given to the installation.
并输入安装的初始密码。
-
In Mysql terminal change password:
在Mysql终端更改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';
mysql>通过“MyNewPassword”识别用户“root”@“localhost”;
#8
10
If you have forgot the MySQL root password, can’t remember or want to break in….. you can reset the mysql database password from the command line in either Linux or OS X as long as you know the root user password of the box you are on:
如果你忘记了MySQL的根密码,不记得或者想要断开。您可以在Linux或OS X的命令行中重新设置mysql数据库密码,只要您知道您所在的框的根用户密码:
(1) Stop MySQL
(1)停止MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
(2) Start it in safe mode:
(2)以安全模式启动:
sudo mysqld_safe --skip-grant-tables
(3) This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
(3)这将是一个持续的命令,直到进程完成后,再打开另一个shell/终端窗口,登录时没有密码:
mysql -u root
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
In the UPDATE command above just replace the 'password' with your own new password, make sure to keep the quotation marks
在更新命令中,只需用你自己的新密码替换“密码”,确保保留引号。
(4) Save and quite
(4)保存并相当
FLUSH PRIVILEGES;
\q
(5) Start MySQL
(5)启动MySQL
sudo /usr/local/mysql/support-files/mysql.server start
#9
5
When I installed OS X Yosemite,I got problem with Mysql. I tried lot of methods but none worked. I actually found a quite easy way. Try this out.
当我安装OS X Yosemite时,我遇到了Mysql的问题。我尝试了很多方法,但都没有用。我找到了一个很简单的方法。试试这个。
- First log in terminal from su privileges.
- 首先从su特权登录到终端。
sudo su
sudo苏
- stop mysql
- 停止mysql
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files / mysql。服务器停止
- start in safe mode:
- 以安全模式启动:
sudo mysqld_safe --skip-grant-tables
sudo mysqld_safe——skip-grant-tables
- open another terminal, log in as su privileges than, log in mysql without password
- 打开另一个终端,以su特权登录,不使用密码登录mysql。
mysql -u root
mysql - u根
- change the password
- 更改密码
UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
更新mysql。用户设置密码=密码('new_password'),用户='root';
- flush privileges
- 冲洗的特权
FLUSH PRIVILEGES;
冲洗特权;
- You are done now
- 你现在做的
#10
1
If you forgot your password or want to change it to your mysql:
如果你忘记了密码,或者想把密码改到你的mysql:
- start your terminal and enter:
- 启动终端,进入:
sudo su
- Enter pass for you system
- 输入pass for you系统。
- Stop your mysql:
- 停止你的mysql:
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:
- 修改你的mysql密码:
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
where "new_password" - your new pass. You don't need old pass for mysql.
“new_password”-你的新密码。你不需要mysql的旧密码。
- Flush, quit and check your new pass:
- 冲洗,退出,检查你的新通行证:
FLUSH PRIVILEGES;
- Close all windows and check your new pass for mysql. Good luck.
- 关闭所有窗口,检查你的新密码。祝你好运。
#11
1
If you can't remember your password, @radtek's answer worked for me except in my case I had set up MySQL using brew which meant that steps 1 and 2 of his answer had to be changed to:
如果你不记得你的密码,@radtek的回答对我起作用了,除非我用brew来设置MySQL,这意味着他的回答的第1步和第2步必须改为:
-
/usr/local/bin/mysql.server stop
/usr/local/bin/mysql.服务器停止
-
/usr/local/bin/mysqld_safe --skip-grant-tables
/usr/local/bin/mysqld_safe——skip-grant-tables
Note: the lack of sudo
.
注意:sudo的缺乏。
#12
0
Stopping MySQL Server
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files / mysql。服务器停止
Starting MySQL in safe mode
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
sudo /usr/local/mysql/bin/mysqld_safe——skip-grant-tables &
Changing the root password
/usr/local/mysql/bin/mysql -u root
/usr/local/mysql/bin/mysql - u根
use mysql;
UPDATE user SET authentication_string=PASSWORD('NEW_PASSWORD') WHERE user='root';
FLUSH PRIVILEGES;
exit
Testing
Run /usr/local/mysql/bin/mysql -u root
运行/usr/local/mysql/bin/mysql - u根
Now enter the new password to start using MySQL.
现在输入新口令,开始使用MySQL。
#1
279
Try the command FLUSH PRIVILEGES
when you log into the MySQL terminal. If that doesn't work, try the following set of commands while in the MySQL terminal
当您登录到MySQL终端时,尝试使用命令刷新特权。如果这不起作用,请在MySQL终端中尝试以下命令集。
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Change out NEWPASSWORD with whatever password you want. Should be all set!
用你想要的密码修改新密码。应该都准备好了!
Update: As of MySQL 5.7, the password
field has been renamed authentication_string
. When changing the password, use the following query to change the password. All other commands remain the same:
更新:在MySQL 5.7中,密码字段被重命名为authentication_string。在更改密码时,使用以下查询更改密码。所有其他命令保持不变:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
#2
166
If you don't remember the password you set for root and need to reset it, follow these steps:
如果您不记得为root设置的密码,需要重置它,请按照以下步骤操作:
- Stop the mysqld server, this varies per install
- 停止mysqld服务器,每个安装都不同。
- Run the server in safe mode with privilege bypass
- 使用权限绕过的安全模式运行服务器。
sudo mysqld_safe --skip-grant-tables;
sudo mysqld_safe——skip-grant-tables;
- In a new window connect to the database, set a new password and flush the permissions & quit:
- 在一个新窗口连接到数据库,设置一个新密码并刷新权限&退出:
mysql -u root
mysql - u根
For MySQL older than MySQL 5.7 use:
对于MySQL超过MySQL 5.7的使用:
UPDATE mysql.user SET Password=PASSWORD('your-password') WHERE User='root';
更新mysql。用户设置密码=密码('your-password'),用户='root';
For MySQL 5.7+ use:
MySQL 5.7 +使用:
USE mysql;
使用mysql;
UPDATE mysql.user SET authentication_string=PASSWORD("your-password") WHERE User='root';
更新mysql。用户设置authentication_string=PASSWORD(“your-password”),其中user ='root';
Refresh and quit:
刷新和退出:
FLUSH PRIVILEGES;
冲洗特权;
\q
\问
- Stop the safe mode server and start your regular server back. The new password should work now. Worked like a charm for me :)
- 停止安全模式服务器并启动您的常规服务器。新密码现在应该可以使用了。对我来说是一种魅力
#3
82
Once you've installed MySQL, you'll need to establish the "root" password. If you don't establish a root password, then, well, there is no root password, and you don't need a password to log in.
一旦安装了MySQL,就需要建立“根”密码。如果您没有建立根密码,那么,没有根密码,您不需要密码登录。
So, that being said, you need to establish a root password.
因此,您需要建立一个根密码。
Using terminal enter the following:
使用终端输入如下:
Installation: Set root user password:
/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE
If you've made a mistake, or need to change the root password use the following:
如果您犯了错误,或者需要更改根密码,请使用以下内容:
Change root password:
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
#4
31
The instructions provided in the mysql website is so clear, than the above mentioned
mysql网站提供的说明非常清晰,比上面提到的要清楚。
1. sudo /usr/local/mysql/support-files/mysql.server stop
2) sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
3) /usr/local/mysql/support-files/mysql
4) mysql> FLUSH PRIVILEGES;
5) mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
6) Ctrl + z
7) sudo /usr/local/mysql/support-files/mysql.server start
8) /usr/local/mysql/support-files/mysql -u root -p
9) enter the new password i.e MyNewPass
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
#5
19
-
Stop the mysqld server. Typically this can be done from 'System Prefrences' > MySQL > 'Stop MySQL Server'
停止mysqld服务器。一般来说,这可以从> MySQL > 'Stop MySQL服务器'中完成
-
Start the server in safe mode with privilege bypass From a terminal:
以安全模式启动服务器,特权绕过终端:
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
sudo /usr/local/mysql/bin/mysqld_safe——skip-grant-tables
-
In a new terminal window:
在一个新的终端窗口:
sudo /usr/local/mysql/bin/mysql -u root
sudo /usr/local/mysql/bin/mysql - u根
UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root';
更新mysql。用户设置authentication_string=PASSWORD('NewPassword'),用户='root';
FLUSH PRIVILEGES;
冲洗特权;
\q
\问
-
Stop the mysqld server again and restart it in normal mode.
再次停止mysqld服务器并在正常模式下重新启动它。
#6
15
In the terminal, write mysql -u root -p
and hit Return. Enter the current mysql password that you must have noted down. And set the password SET PASSWORD = PASSWORD('new_password');
在终端中,编写mysql -u root -pand点击返回。输入您必须记下的当前mysql密码。设置密码设置密码=密码('new_password');
Please refer to this documentation here for more details.
更多细节请参考这里的文档。
#7
13
For new Mysql 5.7 for some reason bin commands of Mysql not attached to the shell:
对于新的Mysql 5.7,由于某些原因,Mysql的bin命令没有附加到shell中:
-
Restart the Mac after install.
安装后重新启动Mac。
-
Start Mysql:
Mysql开始:
System Preferences > Mysql > Start button
系统首选> Mysql >启动按钮。
-
Go to Mysql install folder in terminal:
到终端的Mysql安装文件夹:
$ cd /usr/local/mysql/bin/
$ cd /usr/local/mysql/bin/
-
Access to Mysql:
对Mysql的访问:
$ ./mysql -u root -p
$ ./mysql -u root -p。
and enter the initial password given to the installation.
并输入安装的初始密码。
-
In Mysql terminal change password:
在Mysql终端更改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';
mysql>通过“MyNewPassword”识别用户“root”@“localhost”;
#8
10
If you have forgot the MySQL root password, can’t remember or want to break in….. you can reset the mysql database password from the command line in either Linux or OS X as long as you know the root user password of the box you are on:
如果你忘记了MySQL的根密码,不记得或者想要断开。您可以在Linux或OS X的命令行中重新设置mysql数据库密码,只要您知道您所在的框的根用户密码:
(1) Stop MySQL
(1)停止MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
(2) Start it in safe mode:
(2)以安全模式启动:
sudo mysqld_safe --skip-grant-tables
(3) This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
(3)这将是一个持续的命令,直到进程完成后,再打开另一个shell/终端窗口,登录时没有密码:
mysql -u root
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
In the UPDATE command above just replace the 'password' with your own new password, make sure to keep the quotation marks
在更新命令中,只需用你自己的新密码替换“密码”,确保保留引号。
(4) Save and quite
(4)保存并相当
FLUSH PRIVILEGES;
\q
(5) Start MySQL
(5)启动MySQL
sudo /usr/local/mysql/support-files/mysql.server start
#9
5
When I installed OS X Yosemite,I got problem with Mysql. I tried lot of methods but none worked. I actually found a quite easy way. Try this out.
当我安装OS X Yosemite时,我遇到了Mysql的问题。我尝试了很多方法,但都没有用。我找到了一个很简单的方法。试试这个。
- First log in terminal from su privileges.
- 首先从su特权登录到终端。
sudo su
sudo苏
- stop mysql
- 停止mysql
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files / mysql。服务器停止
- start in safe mode:
- 以安全模式启动:
sudo mysqld_safe --skip-grant-tables
sudo mysqld_safe——skip-grant-tables
- open another terminal, log in as su privileges than, log in mysql without password
- 打开另一个终端,以su特权登录,不使用密码登录mysql。
mysql -u root
mysql - u根
- change the password
- 更改密码
UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
更新mysql。用户设置密码=密码('new_password'),用户='root';
- flush privileges
- 冲洗的特权
FLUSH PRIVILEGES;
冲洗特权;
- You are done now
- 你现在做的
#10
1
If you forgot your password or want to change it to your mysql:
如果你忘记了密码,或者想把密码改到你的mysql:
- start your terminal and enter:
- 启动终端,进入:
sudo su
- Enter pass for you system
- 输入pass for you系统。
- Stop your mysql:
- 停止你的mysql:
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:
- 修改你的mysql密码:
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
where "new_password" - your new pass. You don't need old pass for mysql.
“new_password”-你的新密码。你不需要mysql的旧密码。
- Flush, quit and check your new pass:
- 冲洗,退出,检查你的新通行证:
FLUSH PRIVILEGES;
- Close all windows and check your new pass for mysql. Good luck.
- 关闭所有窗口,检查你的新密码。祝你好运。
#11
1
If you can't remember your password, @radtek's answer worked for me except in my case I had set up MySQL using brew which meant that steps 1 and 2 of his answer had to be changed to:
如果你不记得你的密码,@radtek的回答对我起作用了,除非我用brew来设置MySQL,这意味着他的回答的第1步和第2步必须改为:
-
/usr/local/bin/mysql.server stop
/usr/local/bin/mysql.服务器停止
-
/usr/local/bin/mysqld_safe --skip-grant-tables
/usr/local/bin/mysqld_safe——skip-grant-tables
Note: the lack of sudo
.
注意:sudo的缺乏。
#12
0
Stopping MySQL Server
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files / mysql。服务器停止
Starting MySQL in safe mode
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
sudo /usr/local/mysql/bin/mysqld_safe——skip-grant-tables &
Changing the root password
/usr/local/mysql/bin/mysql -u root
/usr/local/mysql/bin/mysql - u根
use mysql;
UPDATE user SET authentication_string=PASSWORD('NEW_PASSWORD') WHERE user='root';
FLUSH PRIVILEGES;
exit
Testing
Run /usr/local/mysql/bin/mysql -u root
运行/usr/local/mysql/bin/mysql - u根
Now enter the new password to start using MySQL.
现在输入新口令,开始使用MySQL。