我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?
我正在跟踪这个链接,但我在本地没有directadmin目录。
我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?
我正在跟踪这个链接,但我在本地没有directadmin目录。
你找不到它。它存储在一个数据库中,您需要根密码才能访问该数据库,即使您以某种方式获得了访问权限,它也会使用单向散列进行散列。您可以重置:如何重置Root用户密码
根据MySql版本的不同,该过程有所不同。按照您的版本所描述的步骤进行操作:
HINTS - Read before the instructions page for your version of MySql* In step 5: Instead of run CMD, create a shortcut on your desktop calling CDM.exe. Then right-click on the shortcut and select "Execute as Administrator". In step 6: Skip the first proposed version of the command and execute the second one, the one with the --defaults-file parameter Once you execute the command, if everything is ok, the CMD window remains open and the command of step 6 continues executing. Simply close the window (click 'x'), and then force close MySQl from the Task Manager. Delete the file with the SQL commands, and start again MySQL. The password must be changed now.
5.0 http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
5.1 http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html
…只需在链接中更改版本(5.5,5.6,5.7)
您无法查看散列后的密码;你唯一能做的就是重置!
停止MySQL:
sudo service mysql stop
or
$ sudo /usr/local/mysql/support-files/mysql.server stop
以安全模式启动:
$ sudo mysqld_safe --skip-grant-tables
(上面一行是整个命令)
这将是一个持续的命令,直到进程结束,所以打开另一个shell/终端窗口,登录时不需要密码:
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
MySQL 5.7及以上版本:
mysql> use mysql;
mysql> update user set authentication_string=password('password') where user='root';
退出MySQL命令行:
mysql> exit
在正常模式下重启MySQL,首先停止安全模式实例:
$ mysqladmin -u root -p shutdown # (when prompted, enter the new password just set)
$ sudo service mysql start
or
$ sudo /usr/local/mysql/support-files/mysql.server start
你的新密码是“password”。
多亏了@thusharaK,我可以在不知道旧密码的情况下重置根密码。
在ubuntu上,我做了以下操作:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking
然后在新的终端运行mysql:
mysql -u root
并执行如下命令修改密码:
UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;
在MySQL 5.7中,MySQL中的password字段。用户表字段被删除,现在字段名是'authentication_string'。
退出mysql安全模式,启动mysql服务:
mysqladmin shutdown
sudo service mysql start
除非包管理器要求您在安装期间输入根密码,否则默认的根密码是空字符串。要连接到新安装的服务器,输入:
shell> mysql -u root --password=
mysql>
要更改密码,请返回unix shell并输入:
shell> mysqladmin -u root --password= password root
新密码为“root”。现在连接到服务器:
shell> mysql -u root --password=
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
哎呀,密码改了。使用新的根:
shell> mysql -u root --password=root
...
blah, blah, blah : mysql welcome banner
...
mysql>
宾果!做一些有趣的事情
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
莫里斯
除了其他答案外,在cpanel安装中,mysql根密码存储在一个名为/root/.my.cnf.的文件中(cpanel服务在更改时将其重置,所以这里的其他答案不会有帮助)
在你的“主机名”中。在MySQL工作的数据文件夹中的err文件中,尝试寻找以以下开头的字符串:
“为roor@localhost生成临时密码”
你可以使用
less /mysql/data/dir/hostname.err
然后使用斜杠命令,后面跟着要查找的字符串
/"A temporary password"
然后按n,进入下一个结果。
MySQL 5.7及以上版本在MySQL日志文件中保存root。
请试试这个:
sudo grep 'temporary password' /var/log/mysqld.log
在Windows系统下,请按照以下步骤重置密码
从任务管理器中停止Mysql服务 创建一个文本文件并粘贴下面的语句
MySQL 5.7.5及以前版本: SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yournewpassword');
MySQL 5.7.6及以上版本: ALTER USER 'root'@'localhost'
保存为mysql-init.txt,并将其放在“C”盘。 打开命令提示符并粘贴以下内容
C:\\ > mysqld——init-file=C:\\mysql-init.txt
这里提供的答案似乎对我不起作用,事实证明,诀窍是: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
(完整的答案在这里:在MySQL 5.7用" plugin: auth_socket "修改用户密码)
有一件事绊倒了我在一个新的MySQL安装,并想知道为什么我不能得到默认密码工作,为什么甚至重置方法不起作用。 在Ubuntu 18上,MySQL服务器的最新版本在默认情况下根本不使用root用户的密码认证。这意味着不管你设置它为什么,它都不会让你使用它。它期望您从特权套接字登录。
mysql -u root -p
即使您使用了正确的密码,这也不起作用。
相反,你需要使用:
sudo mysql
这将适用于任何密码。 然后输入
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password you want to use';
然后登出,现在它将接受您的密码。
系统:
中佐的Linux 7 位于华盛顿市郊1414区
过程:
Open two shell sessions, logging in to one as the Linux root user and the other as a nonroot user with access to the mysql command. In your root session, stop the normal mysqld listener and start a listener which bypasses password authentication (note: this is a significant security risk as anyone with access to the mysql command may access your databases without a password. You may want to close active shell sessions and/or disable shell access before doing this): # systemctl stop mysqld # /usr/sbin/mysqld --skip-grant-tables -u mysql & In your nonroot session, log in to mysql and set the mysql root password: $ mysql mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass'); Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> quit; In your root session, kill the passwordless instance of mysqld and restore the normal mysqld listener to service: # kill %1 # systemctl start mysqld In your nonroot session, test the new root password you configured above: $ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ... mysql>
我用另一种方法解决了这个问题,这对一些人来说可能更简单。
我这样做是因为我尝试在安全模式下启动,但无法连接到错误: ERROR 2002 (HY000):无法通过socket '/var/run/mysqld/mysqld连接到本地MySQL服务器。袜子”(2)
我所做的就是以root用户正常连接:
$ sudo mysql -u root
然后我创建了一个新的超级用户:
mysql> grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword' with grant option;
mysql> quit
然后以myuser身份登录
$ mysql -u myuser -p -h localhost
尝试更改密码没有给我任何错误,但对我没有任何帮助,所以我放弃并重新创建根用户
mysql> drop user 'root'@'localhost;
mysql> mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'mypassword' with grant option;
根用户现在正在使用新密码
我被这个问题困扰了几分钟,下面是唯一可行的解决方案: https://phoenixnap.com/kb/access-denied-for-user-root-localhost
sudo mysql ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password Mysql -u root -p
如果您在过去已经设置了密码,mysql -uroot -p解决方案将不起作用,
在我的例子中,我使用了上面的一些答案来解决这个问题(Ubuntu 16)。结果是:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
如果你在屏幕上看到这段文字: mysqld_safe UNIX套接字文件目录“/var/run/mysqld”不存在。 然后做:
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables & # Look at the & at the end!
进入其他终端设置密码如下:
sudo mysql -u root
mysql> use mysql;
mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('__NEW__PASSWORD__');
mysql> flush privileges;
mysql> quit;
然后重新启动服务并登录
# end mysqld_safe in the other terminal
sudo service mysql start
sudo mysql -h 127.0.0.1 -uroot -p
使用Debian / Ubuntu mysql包,可以使用Debian -sys- maintenance用户登录,该用户拥有所有的权限,密码保存在/etc/mysql/ Debian .cnf文件中
适用于Windows 10下的MySQL 5.5
您无法找到密码,因为它在表中是散列的,所以重置它是唯一的选择。
Lokesh kumar Chippada提供的通过.txt文件导入新密码脚本的解决方案对我不起作用。我发现命令提示符在启动导入后冻结了。
我在my.ini文件中添加了skip-grant-tables,就像tonycoupland在这篇SO帖子上的答案一样。
然后我就可以从命令行登录到mysql了
$ > mysql
然后在mysql中
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
请参见mysql开发页面的“B.3.3.2.3重置Root密码:通用说明”。我现在已经从my.ini文件中删除了skip-grant-tables,并且我可以使用我创建的新密码作为根用户登录。