(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$
You can try reseting the root password by running MySQL in Safe Mode.
Here are the steps:
Stop MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
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..
Log in without a password as root:
mysql -u root
Update root (and any other user's) password)
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
\q
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.
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 &
Related
I just reinstalled MySQL using brew on my mac.
As far as I can see everything works fine, but I cannot change my root password.
When trying I'm getting this error message:
mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
The common way to solve this seems to use (several answers on stack overflow suggest using this):
sudo mysqld_safe --skip-grant-tables
2017-05-19T11:54:35.6NZ mysqld_safe Logging to '/usr/local/var/mysql/mac.err'.
2017-05-19T11:54:35.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2017-05-19T11:54:35.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/mac.pid ended
I stopped the server before executing the command. But this solution does not work for me.
There is also no entry in the error log:
/usr/local/var/mysql/mac.err
I read also about using mysql_secure_installation but there I get just the same error message as when using mysql -u root.
As I mentioned above, I tried already to just uninstall and reinstall it again, but obviously some data remained. So is there maybe any way to manually delete or reset these files?
Solution by OP.
It turned out that:
mysql.server start --skip-grant-tables
(not sure if sudo is necessary)
works for me.
The access denied is because you're not specifying the -p switch
If you know the old password then maybe login to MySql and change it as:
1).login to MySql 2).change to the correct db 3) change the passwd and flush
mysql -u root -p
mysql> use mysql;
mysql> update user set password=PASSWORD("newpass") where User='ENTER-USER-NAME-HERE';
mysql> flush privileges;
mysql> quit
Also, the following works in Linux/Unix systems but i haven't tested it on Mac (may work if you have the clients installed)
mysqladmin -u root -p oldpassword newpass
Reference: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
//If you don't remember the password, to recover it check this out(bottom).
https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords
https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/
I downloaded MySQL 5.7.17 for Mac and installed it. I can start and stop the SQL server from my Preferences > MySQL. It is shown as an instance on port 3306 from Workbench so all that seems fine. However, during install toward the end a pop-up window listed a password I was supposed to use. I assumed it would be promptly needed so copied on the clipboard. Few mins later having not been prompted for it yet, I copied something else in the clipboard thus losing it.
I have been trying to get some sort of client of mysql command line so I can enter sql commands, however there is no "Application" installed to use to access the server. I have scoured the MySQL documentation and Stack and beyond, and searched for how to get the password reset, and a mysql client/command line, but all the articles seem to assume you already have access to a "MySQL terminal"/"command line". I only have access to my normal Mac Terminal, and most commands in the normal Terminal window either fail or require the password I don't have, for example:
$ mysqld --skip-grant-tables
-bash: mysqld: command not found
$ mysql -u root -p
-bash: mysql: command not found
$ sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
Password: (this is probably the password I was given that got overwritten? When I try the admin password of the machine it sends me back to the prompt)
$ sudo mysqld_safe --skip-grant-tables (after I'd stopped the server)
sudo: mysqld_safe: command not found
Can somebody please help me figure out how to get to a "MySql Terminal" and if I need this password that got overwritten, how to reset it? (it seems like uninstalling MySQL to repeat the steps and this time take better care of the password is actually horrendously difficult / no uninstall protocol?).
Thank you so very much.
--- Update: I used the How To Uninstall suggested by Josh M and then re-installed. This time I saved the password (so far, not sure how / where I need to use it). However, I must really be missing something b/c I still can't get access to mysql.
/usr/local/mysql/bin/mysql
ERROR 1045 (28000): Access denied for user 'Robert'#'localhost' (using password: NO)
Then I did $ export PATH=$PATH:/usr/local/mysql/bin but I still get ERROR 1045.
Try these set of commands
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
/usr/local/mysql/bin/mysql
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'YOUR_NEW_PASSWORD';
EXIT;
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start
$ mysql -u root -p
$ Enter Password: 👉🏻 ENTER_YOUR_NEW_PASSWORD_HERE 👈🏻
And enjoy 🎉
There's a tutorial for resetting passwords here: https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords
Your MySQL command line interface (cli) is probably at:
/usr/local/mysql/bin/mysql
Honestly it might be better to reinstall. There's an SO on that: How do you uninstall MySQL from Mac OS X?
I just installed mysql fresh on my computer. I never set any passwords nor have I set up any databases yet. Every command I try to enter into mysql is blocked because the system keeps prompting me for a password which I don't have. I've tried following many steps to reset the root password but often times when I enter a command such as:
./mysqld --skip-grant-tables --skip-networking
My terminal says something along the lines of (Errcode: 13 - Permission denied).
So can anyone suggest some file I should check or some commands I should try to set/reset the password?
Thank you
Not sure which steps you have taken this far based on your post, what OS you installed on (I am making an assumption it was on a linux distro), or whether it was from source or not but here are the steps you need to rest the root password:
How to reset the root password for mysql:
Stop mysql:
1. service mysql stop
Run mysql with skip grants to be able to login without any password
2. mysqld_safe --skip-grant-tables &
Login as root
3. mysql -u root
4. mysql commands:
mysql> use mysql;
mysql> update user set password=PASSWORD("YourPWHere") where User='root';
mysql> flush privileges;
mysql> quit
Stop mysql
5. service mysql stop
Start mysql normally:
6. service mysql start
Try to login using your new password:
7. mysql -u root -p
If that fails...I would just reinstall fresh...
During my salary instalation you should enter a password at some stage so long think you must have left the default password which is root if this doesn't work Uninstaller and reinstall paying special attention to every step
I'm new to setting up my own database server and linux server, but I'm working on a project that needs to use phpCake and mysql. I have a turnkey linux install of LAMP, with phpCake installed on it. My Cake install is fine, however I can not get into mysql.
mysql command yields error 1045, access denied for user root#localhost using password: no
mysql -u root -p
'rootpasswordhere'
yeilds the same thing, except using password:yes
I've read many fixes involving stoping mysql and setting a new password. I've had none of those work for me. The mysql stop command is denied in the same way the mysql command is. When I use service stop mysql my input cursor gets strange and no longer captures any input.
I'd love any help or input. I'll try out any of the fixes out there again and detail what happens. I'm sorry if this has been answered before, but trying the fixes I've found over the last few hours don't seem to work. Unsure if it is me, or my actual problem.
Thanks!
Depending on which linux you are running:
Stop service:
sudo service mysqld stop
Run these commands to write a temporary SQL file (/tmp/my.sql):
sudo echo "UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';" > /tmp/my.sql
sudo echo "FLUSH PRIVILEGES;" >> /tmp/my.sql
Start the service with script:
sudo /usr/bin/mysqld_safe --init-file=/tmp/my.sql &
---------------------------------------------------------------------------------^ The ampersand runs the process in the background allowing you to continue using the terminal.
Now you should be able to connect with your new root password MyNewPass
Note: Be sure to a) change the root password and b) remove /tmp/my.sql once completed.
Ive had mysql up and running for month now. I was using it yesterday, and today I go to login via phpmyadmin and the command line and I suddenly can't. Its as if someone changed my password overnight or something. Im trying to login using the root user. What do I do?
Edit
This is mysql just running on my local laptop for development. The only account on it is the root account, and no caps lock is not on.
http://www.cyberciti.biz/tips/recover-mysql-root-password.html says this five step process will work, try at your own risk obviously. This source also has essentially the same steps. This likely won't work on windows, but something similar should http://www.debian-administration.org/articles/442
Stop mysql service using /etc/init.d/mysql stop
Start mysql without password using mysqld_safe --skip-grant-tables &
Connect to the server using mysql -u root
Change the root password:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Stop the Server: /etc/init.d/mysql stop
Start the Server: /etc/init.d/mysql start
Test: mysql -u root -p
I used the link raina77ow provided and followed the instructions to reset my password and it works now.
Scrolling down to section C.5.4.1.3. Resetting the Root Password: Generic Instructions was particularly helpful.