我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?
我正在跟踪这个链接,但我在本地没有directadmin目录。
我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?
我正在跟踪这个链接,但我在本地没有directadmin目录。
当前回答
适用于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,并且我可以使用我创建的新密码作为根用户登录。
其他回答
您无法查看散列后的密码;你唯一能做的就是重置!
停止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”。
你可以查看mysql根密码,好吧,我已经在mysql 5.5上尝试过了,所以不知道其他新版本是否工作良好
nano ~/.my.cnf
除非包管理器要求您在安装期间输入根密码,否则默认的根密码是空字符串。要连接到新安装的服务器,输入:
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服务在更改时将其重置,所以这里的其他答案不会有帮助)
系统:
中佐的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>