Forgot MySQL root password reset under Mac

Source: Internet
Author: User
Tags mysql in safe mode administrator password sub account

Long before the installation of MySQL in Mac this machine, suddenly to use the time, found how also connect not on the Web to find a lot of tutorial attempts are unsuccessful, finally found an attempt to succeed. Thanks to the Yumbo Master's share reproduced in the following record, Source: http://blog.csdn.net/u014410695/article/details/50630233

The following methods are pro-test effective, the process using the tool only Mac terminal without Workbench

When we connect the MySQL database via the terminal, we will see this information

ERROR 1045: Access denied for user: ‘[email protected]‘ (Using password: NO)

Or

ERROR 1045: Access denied for user: ‘[email protected]‘ (Using password: YES)

One way to resolve the above error is to reset our MySQL root password.

1. In the terminal enter the following command to close the running MySQL, if MSYQL is not running can skip, need to enter MySQL password. If the MySQL password is forgotten, you can close it directly through system Preferences!

/usr/local/mysql/bin/mysqladmin -u root -p shutdown

The system will be set to off.

2. Go to the MySQL bin directory to execute the following command

cd /usr/local/mysql/bin$ sudo su  

Then enter the administrator password to see

sh-3.2# 

We then enter the following command to run MySQL in safe mode

sh-3.2#./mysqld_safe --skip-grant-tables &

Run the end we turn on Mac System Preferences, select MSYQL, we'll find MySQL rerun

Back to Terminal click Command + N to reopen a terminal
Input

-u -root

That's when we don't need a password to get into MySQL.

Your MySQL Connection ID is57ServerVersion5.7.10 MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/ or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Names may trademarks of their respectiveowners. Type  ' help; ' or  ' \h ' for help. Type  ' \c ' to clear the current input statement.mysql>         

Note: There are times when it will not come in, this time can try to restart the Mac computer, the specific reason I am not clear.

3. Change the root password
First execute the following command in order to be able to modify any password

mysql> FLUSH PRIVILEGES;

Then execute the SQL statement that modifies the password, where the qsd19001008 can replace the password you want to change.

SET PASSWORD FOR [email protected]‘localhost‘ = PASSWORD(‘qsd19001008‘);

If your sub account can log in msyql you can also try the following methods

SET Password=PASSWORD(‘newpwd‘) WHERE User=‘root‘;

Or

mysql>USE mysql   SET Password = PASSWORD(‘newpwd‘)   WHERE Host = ‘localhost‘ AND User = ‘root‘;

Or
mysql>USE mysql   SET Password = PASSWORD(‘newpwd‘)   WHERE Host = ‘%‘ AND User = ‘root‘;

Last Refresh

FLUSH PRIVILEGES;

Control+d launch MySQL, and then close the Safe Mode database, here to enter you just set the data password just fine

/usr/local/mysql/bin/mysqladmin -u root -p shutdown

So far, you've recovered your MySQL password.

Start the MySQL database normally and enter the password you just set qsd19001008

/usr/local/mysql/share/mysql.server start

If the above command does not execute, the same as in System Preferences to open the MySQL server.

Finally execute the following Terminal command, and then enter the password that you just set qsd19001008 we can get to MySQL properly.

$mysql -u root -p

Forgot MySQL root password reset under Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.