我使用下面的命令找到正在运行的
mysql
服务:
$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
但是我忘记了密码,或者可能是我没有设置。
如何设置MySQL的密码?
还有
mysqld_safe
服务正在运行是否意味着密码没有设置?
sudo /etc/init.d/mysql stop
mysqld
选项启动 --skip-grant-tables
守护进程:
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
FLUSH PRIVILEGES;
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = 'localhost' AND User = 'root';
root
帐户:
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = '%' AND User = 'root';
对于任一方法,一旦收到指示查询成功的消息(受影响的一行或多行),则刷新权限:
FLUSH PRIVILEGES;
mysqld
进程并以经典方式重新启动它:
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start