如何在mysqld_safe正在运行的场景中设置mysql的密码? [英] How can I set the mysql's password in the mysqld_safe is running scenario?
问题描述
我使用贝娄命令找到正在运行的 mysql
服务.
I use bellow command find the running mysql
service.
$ps -ef | grep mysqld
501 4512 1 0 12:19 pm ?? 0:00.06 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log
501 4849 4512 0 12:19 pm ?? 0:00.29 /Applications/MAMP/Library/bin/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql56 --plugin-dir=/Applications/MAMP/Library/lib/plugin --log-error=/Applications/MAMP/logs/mysql_error_log.err --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --socket=/Applications/MAMP/tmp/mysql/mysql.sock --port=8889
但是我忘记了密码,或者我没有设置密码.
But I forget the password, or maybe I did not set it.
现在如何设置mysql的密码?以及 mysqld_safe
服务是否正在运行意味着未设置密码?
now how can I set my mysql's password?
and whether the mysqld_safe
service is running means the password did not set?
推荐答案
1-使用以下命令停止mysql demon进程:
1-Stop the mysql demon process using this command :
sudo/etc/init.d/mysql stop
sudo /etc/init.d/mysql stop
2-使用--skip-grant-tables选项和此命令启动mysqld妖进程
2-Start the mysqld demon process using the --skip-grant-tables option with this command
sudo/usr/sbin/mysqld --skip-grant-tables --skip-networking&
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
3-使用此命令启动mysql客户端进程
3-start the mysql client process using this command
mysql -u根
4-在mysql提示符下执行此命令可以更改任何密码
4-from the mysql prompt execute this command to be able to change any password
冲洗特权;
5-然后重置/更新您的密码
5-Then reset/update your password
为root @'localhost'= PASSWORD('password');设置密码
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
6-如果您有一个可以从任何地方连接的mysql根帐户,则还应该执行以下操作:
6-If you have a mysql root account that can connect from everywhere, you should also do:
更新mysql.user SET密码= PASSWORD('newpwd'),其中User ='root';
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
7种替代方法:
使用mysql更新用户SET密码= PASSWORD('newpwd')Host ='localhost'和User ='root';
USE mysql UPDATE user SET Password = PASSWORD('newpwd') WHERE Host = 'localhost' AND User = 'root';
8-并且,如果您具有可以从任何地方访问的root帐户:
8-And if you have a root account that can access from everywhere:
使用mysql更新用户SET密码= PASSWORD('newpwd')主机='%'且用户='根';
USE mysql UPDATE user SET Password = PASSWORD('newpwd') WHERE Host = '%' AND User = 'root';
对于这两种方法,一旦收到一条指示查询成功的消息(受影响的一行或多行),则刷新权限:
For either method, once have received a message indicating a successful query (one or more rows affected), flush privileges:
冲洗特权;
9-然后停止mysqld进程并以经典方式重新启动它:
9-Then stop the mysqld process and relaunch it with the classical way:
sudo/etc/init.d/mysql stop
sudo /etc/init.d/mysql stop
sudo/etc/init.d/mysql start
sudo /etc/init.d/mysql start
这篇关于如何在mysqld_safe正在运行的场景中设置mysql的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!