在 macports 中重置 mysql5 root 密码

发布于 2024-11-13 12:20:36 字数 1693 浏览 5 评论 0原文

我刚刚通过 macports 1.9.2 在 Snow Leopard 上安装了 macports。现在我无法使用mysql,因为好像我不知道密码。

$ sudo mysql5 -u root -p 
Enter password:  
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

我不确定这是否是安装或使用中的错误,或者我只是忘记了密码,但我想我需要重置密码。怎么做呢?

更新:我可以启动和停止我的 MySql 服务器,所以它不应该被破坏,但我没有像 $ sudo /opt/local/lib/mysql5/bin/mysqld_safe5 这样的命令。

$ ls /opt/local/lib/mysql5/bin/
innochecksum            mysql_client_test       mysql_secure_installation   mysqlbinlog         mysqlimport         ndb_drop_index          ndb_select_all          resolve_stack_dump
msql2mysql          mysql_client_test_embedded  mysql_setpermission     mysqlbug            mysqlshow           ndb_drop_table          ndb_select_count        resolveip
my_print_defaults       mysql_config            mysql_tzinfo_to_sql     mysqlcheck          mysqlslap           ndb_error_reporter      ndb_show_tables
myisam_ftdump           mysql_convert_table_format  mysql_upgrade           mysqld_multi            mysqltest           ndb_mgm             ndb_size.pl
myisamchk           mysql_find_rows         mysql_waitpid           mysqld_safe         mysqltest_embedded      ndb_print_backup_file       ndb_test_platform
myisamlog           mysql_fix_extensions        mysql_zap           mysqldump           ndb_config          ndb_print_schema_file       ndb_waiter
myisampack          mysql_fix_privilege_tables  mysqlaccess         mysqldumpslow           ndb_delete_all          ndb_print_sys_file      perror
mysql               mysql_install_db        mysqladmin          mysqlhotcopy            ndb_desc            ndb_restore         replace

I've just installed macports through macports 1.9.2 on Snow Leopard. Now I can't use mysql because it seems as if I didn't know the password.

$ sudo mysql5 -u root -p 
Enter password:  
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I'm not sure if this is some error in the install or usage, or I just forgot the password, but I think I need to reset the password. How to do it?

UPDATE: I can start and stop my MySql server, so it shouldn't be broken, but I don't have a command like $ sudo /opt/local/lib/mysql5/bin/mysqld_safe5.

$ ls /opt/local/lib/mysql5/bin/
innochecksum            mysql_client_test       mysql_secure_installation   mysqlbinlog         mysqlimport         ndb_drop_index          ndb_select_all          resolve_stack_dump
msql2mysql          mysql_client_test_embedded  mysql_setpermission     mysqlbug            mysqlshow           ndb_drop_table          ndb_select_count        resolveip
my_print_defaults       mysql_config            mysql_tzinfo_to_sql     mysqlcheck          mysqlslap           ndb_error_reporter      ndb_show_tables
myisam_ftdump           mysql_convert_table_format  mysql_upgrade           mysqld_multi            mysqltest           ndb_mgm             ndb_size.pl
myisamchk           mysql_find_rows         mysql_waitpid           mysqld_safe         mysqltest_embedded      ndb_print_backup_file       ndb_test_platform
myisamlog           mysql_fix_extensions        mysql_zap           mysqldump           ndb_config          ndb_print_schema_file       ndb_waiter
myisampack          mysql_fix_privilege_tables  mysqlaccess         mysqldumpslow           ndb_delete_all          ndb_print_sys_file      perror
mysql               mysql_install_db        mysqladmin          mysqlhotcopy            ndb_desc            ndb_restore         replace

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风透绣罗衣 2024-11-20 12:20:36

首先,您需要确保数据库已停止:

$ sudo /opt/local/share/mysql5/mysql/mysql.server stop 

现在您应该通过mysqld_safe命令在后台启动数据库:

$ sudo /opt/local/lib/mysql5/bin/mysqld_safe --skip-grant-tables &

现在服务器正在使用运行-- Skip-grant-tables 标志,您可以在没有密码的情况下连接到它并完成工作:

 $ sudo mysql5 --user=root mysql
 Enter password:

 mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
 Query OK, 2 rows affected (0.04 sec)
 Rows matched: 2  Changed: 2  Warnings: 0

 mysql> flush privileges;
 Query OK, 0 rows affected (0.02 sec)

 mysql> exit
 Bye

现在您已经完成了,您只需要停止服务器,以便您可以返回运行安全的 MySQL 服务器有密码限制。首先,通过输入“fg”将您启动的服务器置于前台,然后按“Ctrl+c”将其终止。

现在您可以启动服务器:

$ sudo /opt/local/share/mysql5/mysql/mysql.server start

First of all you will need to ensure that your database is stopped:

$ sudo /opt/local/share/mysql5/mysql/mysql.server stop 

Now you should start up the database in the background, via the mysqld_safe command:

$ sudo /opt/local/lib/mysql5/bin/mysqld_safe --skip-grant-tables &

Now that the server is running with the --skip-grant-tables flag you can connect to it without a password and complete the job:

 $ sudo mysql5 --user=root mysql
 Enter password:

 mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
 Query OK, 2 rows affected (0.04 sec)
 Rows matched: 2  Changed: 2  Warnings: 0

 mysql> flush privileges;
 Query OK, 0 rows affected (0.02 sec)

 mysql> exit
 Bye

Now that you've done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place. First of all bring the server you started into the foreground by typing "fg", then kill it by pressing "Ctrl+c" afterwards.

This will now allow you to start the server:

$ sudo /opt/local/share/mysql5/mysql/mysql.server start
冷情 2024-11-20 12:20:36

我也有同样的问题。当尝试重置密码时(按照 develroot 的建议),我还得到:

Rows matched: 0 Changed: 0 Warnings: 0

所以 root 用户从来没有被创建过。除了 develroot 的回答之外,我还采取了以下步骤:

flush privileges;
CREATE USER 'root'@'localhost' IDENTIFIED BY 'root'
GRANT ALL ON *.* TO 'root'@'localhost'

I had the same problem. When trying to reset the password (as develroot suggested), I also got:

Rows matched: 0 Changed: 0 Warnings: 0

So the root user had never been created in the first place. I took the following steps in addition to develroot's answer:

flush privileges;
CREATE USER 'root'@'localhost' IDENTIFIED BY 'root'
GRANT ALL ON *.* TO 'root'@'localhost'
梦一生花开无言 2024-11-20 12:20:36

这是我的修复。

运行此命令后:sudo -u mysql mysql_install_db5

我得到了这个错误:

ERROR: 1004  Can't create file '/var/tmp/#sql180bd_1_0.frm' (errno: 9)
121221  2:06:21 [ERROR] Aborting

与之前的报告相同,我的用户表是空的——所有的mysql表都是空的

最终,我想出了这样做:

  1. < p>以安全模式运行 mysqld。

    sudo /opt/local/bin/mysqld_safe5 --skip-grant-tables &

  2. 登录并删除损坏的mysql数据库

    $mysql5
    $mysql> DROP TABLE mysql;

  3. 以 ROOT 身​​份而不是 mysql 重新运行 mysql_install_db5,这样它至少可以完成工作

    $ sudo -u root mysql_install_db5

  4. 然后返回并 chown -R 中的所有内容/opt/local/var/db/mysql5 到 mysql:mysql ,因为它需要。

    $ sudo chown -R mysql:mysql /opt/local/var/db/mysql5/
    $ sudo chown -R mysql:mysql /opt/local/var/run/mysql5/
    $ sudo chown -R mysql:mysql /opt/local/var/log/mysql5/

  5. 此后一切正常,谢谢。

This is my fix.

After running this: sudo -u mysql mysql_install_db5

I got this error:

ERROR: 1004  Can't create file '/var/tmp/#sql180bd_1_0.frm' (errno: 9)
121221  2:06:21 [ERROR] Aborting

Same as previous reports, my users table was empty --- all the mysql tables were emtpy

Eventually, I figured out to do this:

  1. Run mysqld in safe mode.

    sudo /opt/local/bin/mysqld_safe5 --skip-grant-tables &

  2. Log in and drop the broken mysql database

    $ mysql5
    $ mysql> DROP TABLE mysql;

  3. Re-run the mysql_install_db5 as ROOT rather than mysql so it can at least get the job done

    $ sudo -u root mysql_install_db5

  4. Then go back and chown -R everything in /opt/local/var/db/mysql5 to mysql:mysql as it needs to be.

    $ sudo chown -R mysql:mysql /opt/local/var/db/mysql5/
    $ sudo chown -R mysql:mysql /opt/local/var/run/mysql5/
    $ sudo chown -R mysql:mysql /opt/local/var/log/mysql5/

  5. everything worked just fine after that, thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文