我刚刚在 Snow Leopard 上通过 macports 1.9.2 安装了 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
最佳答案
首先您需要确保您的数据库已停止:
$ 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
关于mysql - 在 macports 中重置 mysql5 root 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6252071/