我刚刚在我的Mac上设置了MySQL,我忘记了我的root密码是什么。(我使用的密码组合很少,而且似乎都没有用)我试过了许多方法,包括尝试在安全模式下重置root密码。似乎没有什么对我有用。
以下是我尝试的一些解决方案中的日志:
1.Normal Login
Yorks-MacBook-Pro:~ yorkwang$ mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Yorks-MacBook-Pro:~ yorkwang$ mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (usingpassword: YES)
2.Safemode密码重置
Yorks-MacBook-Pro:~ yorkwang$ mysqld_safe --skip-grant-tables
2016-07-08T18:37:50.6NZ mysqld_safe Logging to '/usr/local/var/mysql/Yorks-MacBook-Pro.local.err'.
2016-07-08T18:37:51.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
/usr/local/bin/mysqld_safe: line 135: /usr/local/var/mysql/Yorks-MacBook-Pro.local.err: Permission denied
rm: /tmp/mysql.sock: Permission denied
/usr/local/bin/mysqld_safe: line 169: /usr/local/var/mysql/Yorks-MacBook-Pro.local.err: Permission denied
2016-07-08T18:37:51.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/Yorks-MacBook-Pro.local.pid ended
/usr/local/bin/mysqld_safe: line 135: /usr/local/var/mysql/Yorks-MacBook-Pro.local.err: Permission denied
3.Safemode密码重置(关闭MYSQL服务器)
[1]+ Stopped sudo mysqld --skip-grant-tables
Yorks-MacBook-Pro:~ yorkwang$
2016-07-08T18:43:50.807384Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-07-08T18:43:50.809064Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2016-07-08T18:43:50.810163Z 0 [Note] mysqld (mysqld 5.7.11) starting as process 68112 ...
2016-07-08T18:43:50.823374Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2016-07-08T18:43:50.835814Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-07-08T18:43:50.835842Z 0 [Note] InnoDB: Uses event mutexes
2016-07-08T18:43:50.835848Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2016-07-08T18:43:50.835852Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-07-08T18:43:50.837573Z 0 [Note] InnoDB: Number of pools: 1
2016-07-08T18:43:50.839941Z 0 [Note] InnoDB: Using CPU crc32 instructions 2016-07-08T18:43:50.850947Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-07-08T18:43:50.865025Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-07-08T18:43:50.891791Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-07-08T18:43:50.926530Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-07-08T18:43:50.926759Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2016-07-08T18:43:50.958427Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2016-07-08T18:43:50.959275Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-07-08T18:43:50.959287Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-07-08T18:43:50.959505Z 0 [Note] InnoDB: Waiting for purge to start
2016-07-08T18:43:51.014726Z 0 [Note] InnoDB: 5.7.11 started; log sequence number 2494670
2016-07-08T18:43:51.015106Z 0 [Note] InnoDB: Loading buffer pool(s) from /usr/local/var/mysql/ib_buffer_pool
2016-07-08T18:43:51.015947Z 0 [Note] Plugin 'FEDERATED' is disabled.
2016-07-08T18:43:51.029570Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2016-07-08T18:43:51.029602Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2016-07-08T18:43:51.031297Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160708 11:43:51
2016-07-08T18:43:51.033667Z 0 [Warning] CA certificate ca.pem is self signed.
2016-07-08T18:43:51.034667Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2016-07-08T18:43:51.041311Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2016-07-08T18:43:51.041463Z 0 [Note] IPv6 is available.
2016-07-08T18:43:51.041482Z 0 [Note] - '::' resolves to '::';
2016-07-08T18:43:51.041495Z 0 [Note] Server socket created on IP: '::'.
2016-07-08T18:43:51.149448Z 0 [Note] mysqld: ready for connections. Version: '5.7.11' socket: '/tmp/mysql.sock' port: 3306 Homebrew
mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
其他信息:我在OSX 10.11.5上使用macbook pro
答案 0 :(得分:3)
当您尝试在没有授权表的情况下启动MySQL服务器时,您正在接收(多个)Permission Denied
。例如,
/usr/local/bin/mysqld_safe: line 135: /usr/local/var/mysql/Yorks-MacBook-Pro.local.err: Permission denied
这就是为什么你无法连接到服务器(它从来没有机会启动)。
首先,杀死可能已经在运行的任何mysqld_safe
(作为超级用户):
$ sudo killall -TERM mysqld_safe; sleep 5; sudo killall -TERM mysqld
检查过程是否已经死亡:
$ ps -ef | grep mysql
如果没有,并且不关心丢失数据库完整性(可能的数据丢失)发出命令:
$ sudo killall -KILL mysqld_safe; sleep 5; sudo killall -KILL mysqld
然后,尝试使用超级用户权限启动mysqld_safe
(请注意--skip-grant-tables):
$ sudo mysqld_safe --skip-grant-tables
然后连接到MySQL服务器(避免使用mysql unix套接字):
$ mysql -uroot -h 127.0.0.1 --protocol=tcp
然后,在MySQL控制台下:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
mysql> ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY 'MyNewPass';
参考文献: