0

(After two hours of researching how to use mysql commands in the terminal, I can finally post this question, BTW if anyone with macOS is having the same trouble that can't use mysql commands in the terminal, go straight to this straight to this link: solution.)

I have a Mac os Sierra, I'm completely new to MySQL. I first downloaded the workbench and the MySql server, it gave me a temp password, I created a local connection, it worked. Then, I deleted the old connection, and created another connection, it asks for the password, and it wouldn't work, so right now I'm trying to reset and change my mysql password, but I've been having a lot of trouble with it.

Since the SQL office website only has instructions for windows and unix, and I'm rather new to bash, I tried to find solutions somewhere else like this site.

1. Attempt

When I tried the solution from this link site1, as I try the first step, it asks for a password which I don't have, I tried the old password just to try and it didn't work.

YupengdeMacBook-Pro:~ yinyupeng$ sudo /usr/local/mysql/support-files/mysql.server stop
Password:

Then, I realized that I can close my server directly in the MacOS setting, I did that, and I jumped to the second step directly, it still asks for a password:

YupengdeMacBook-Pro:~ yinyupeng$ sudo mysqld_safe --skip-grant-tables
Password:

So I'm stuck here, can't go further with this solution.

2. Attempt

then I tried this site2, but as I type the first line, it tells me this:

YupengdeMacBook-Pro:~ yinyupeng$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Umm... ok, so then I tried to find solutions for that "access denied" error, but with little results.

So I'm not sure what to do now, please help, thank you very much. BTW, my SQL version is:

YupengdeMacBook-Pro:~ yinyupeng$ mysql --version
mysql  Ver 14.14 Distrib 5.7.19, for macos10.12 (x86_64) using  EditLine wrapper
YupengdeMacBook-Pro:~ yinyupeng$ 
Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
yyin
  • 71
  • 1
  • 8
  • 1
    The password it asks for when you try to start mysqld_safe is YOUR password, can you give that another shot? – Ulises André Fierro Sep 11 '17 at 15:46
  • @Ulises André Fierro You mean my Mac password? – yyin Sep 11 '17 at 15:50
  • Yes, whatever password you use to login is the password it's asking for. – Ulises André Fierro Sep 11 '17 at 15:51
  • Thank you, I have a class right now, I'll give it a try and get back to you ASAP. – yyin Sep 11 '17 at 15:57
  • @Ulises André Fierro Hello! I tried it out and it worked! Thank you so much for pointing it out that it's my Mac password that i needed to enter. However, I do have a question I'll ask below – yyin Sep 11 '17 at 18:11
  • @Ulises André Fierro I don't understand why when I deleted the old connection, and created the new connection resulted in wrong password. They are both local servers 127.0.0.1:3306 just the name is different. Will this affect me in the future? Because I've created and deleted multiple connections while I was trying to put in my password, I'm not sure how this will affect me, thank you! – yyin Sep 11 '17 at 18:12

2 Answers2

0

You can try reseting the root password by running MySQL in Safe Mode.

Here are the steps:

  1. Stop MySQL:

    sudo /usr/local/mysql/support-files/mysql.server stop

  2. Start it in safe mode:

    sudo mysqld_safe --skip-grant-tables

This will be an ongoing command until the process is finished so open another shell/terminal window, and..

  1. Log in without a password as root:

    mysql -u root

  2. Update root (and any other user's) password)

    FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; \q

  3. Restart MySQL in normal mode

    sudo /usr/local/mysql/support-files/mysql.server start

Reference: https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/

Note: this is pretty much a copy-paste from the reference link. this is pretty standard reset procedure, but just documented better in that guide compared to mysql reference docs.

CVG
  • 137
  • 7
-1

You can edit your mysql configuration file and add skip-grant-tables to the section [mysqld]

or

Start mysqld and send it to background

mysqld_safe --skip-grant-tables &
aynber
  • 22,380
  • 8
  • 50
  • 63
djadk
  • 74
  • 1
  • 3
  • Sorry, I'm a beginner and I'm not sure what this means. – yyin Sep 11 '17 at 18:00
  • You can edit your MySQL configuration file and add skip-grant-tables to the section [mysqld]: or--- sudo /usr/local/mysql/support-files/mysql.server stop\n sudo mysqld_safe --skip-grant-tables\n mysql -u root – djadk Sep 12 '17 at 18:45