The Question :
239 people think this question is useful
I just installed MySQL on Mac OS X. The next step was setting the root user password, so I did this next:
- Launch the terminal app to access the Unix command line.
Under the Unix prompt I executed these commands:
$ cd /usr/local/mysql/bin
$ ./mysqladmin -u root password 'password'
But, when I execute the command
$ ./mysql -u root
, this is the answer:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 224
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
I can get into the mysql
command line without any password!
Why is this?
The Question Comments :
The Answer 1
324 people think this answer is useful
Try the command FLUSH PRIVILEGES
when you log into the MySQL terminal. If that doesn’t work, try the following set of commands while in the MySQL terminal
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Change out NEWPASSWORD with whatever password you want. Should be all set!
Update: As of MySQL 5.7, the password
field has been renamed authentication_string
. When changing the password, use the following query to change the password. All other commands remain the same:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
Update: On 8.0.15 (maybe already before that version) the PASSWORD() function does not work, as mentioned in the comments below. You have to use:
UPDATE mysql.user SET authentication_string='password' WHERE User='root';
The Answer 2
198 people think this answer is useful
If you don’t remember the password you set for root and need to reset it, follow these steps:
- Stop the mysqld server, this varies per install
- Run the server in safe mode with privilege bypass
sudo mysqld_safe --skip-grant-tables;
- In a new window connect to the database, set a new password and flush the permissions & quit:
mysql -u root
For MySQL older than MySQL 5.7 use:
UPDATE mysql.user SET Password=PASSWORD('your-password') WHERE User='root';
For MySQL 5.7+ use:
USE mysql;
UPDATE mysql.user SET authentication_string=PASSWORD("your-password") WHERE User='root';
Refresh and quit:
FLUSH PRIVILEGES;
\q
- Stop the safe mode server and start your regular server back. The new password should work now. Worked like a charm for me 🙂
The Answer 3
85 people think this answer is useful
Once you’ve installed MySQL, you’ll need to establish the “root” password. If you don’t establish a root password, then, well, there is no root password, and you don’t need a password to log in.
So, that being said, you need to establish a root password.
Using terminal enter the following:
Installation: Set root user password:
/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE
If you’ve made a mistake, or need to change the root password use the following:
Change root password:
cd /usr/local/mysql/bin/
./mysql -u root -p
> Enter password: [type old password invisibly]
use mysql;
update user set password=PASSWORD("NEW_PASSWORD_HERE") where User='root';
flush privileges;
quit
The Answer 4
74 people think this answer is useful
The instructions provided in the mysql website is so clear, than the above mentioned
$ 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
- mysql> FLUSH PRIVILEGES;
- mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass’;
- mysql>
exit
or Ctrl + z
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start
/usr/local/mysql/support-files/mysql -u root -p
- Enter the new password i.e MyNewPass
Reference: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
The Answer 5
60 people think this answer is useful
Stop the mysqld server.
- Mac OSX:
System Preferences
> MySQL
> Stop MySQL Server
- Linux (From Terminal):
sudo systemctl stop mysqld.service
Start the server in safe mode with privilege bypass
- From Terminal:
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
In a new terminal window:
sudo /usr/local/mysql/bin/mysql -u root
This will open the mysql command line. From here enter:
Stop the mysqld server again and restart it in normal mode.
- Mac OSX (From Terminal):
sudo /usr/local/mysql/support-files/mysql.server restart
- Linux Terminal:
sudo systemctl restart mysqld
The Answer 6
22 people think this answer is useful
For new Mysql 5.7 for some reason bin commands of Mysql not attached to the shell:
Restart the Mac after install.
Start Mysql:
System Preferences > Mysql > Start button
Go to Mysql install folder in terminal:
$ cd /usr/local/mysql/bin/
Access to Mysql:
$ ./mysql -u root -p
and enter the initial password given to the installation.
In Mysql terminal change password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';
The Answer 7
16 people think this answer is useful
In the terminal, write mysql -u root -p
and hit Return.
Enter the current mysql password that you must have noted down.
And set the password
SET PASSWORD = PASSWORD('new_password');
Please refer to this documentation here for more details.
The Answer 8
10 people think this answer is useful
If you have forgot the MySQL root password, can’t remember or want to break in….. you can reset the mysql database password from the command line in either Linux or OS X as long as you know the root user password of the box you are on:
(1) Stop MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
(2) Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
(3) This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
mysql -u root
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
In the UPDATE command above just replace the ‘password’ with your own new password, make sure to keep the quotation marks
(4) Save and quite
FLUSH PRIVILEGES;
\q
(5) Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
The Answer 9
5 people think this answer is useful
When I installed OS X Yosemite,I got problem with Mysql. I tried lot of methods but none worked. I actually found a quite easy way. Try this out.
- First log in terminal from su privileges.
sudo su
- stop mysql
sudo /usr/local/mysql/support-files/mysql.server stop
- start in safe mode:
sudo mysqld_safe --skip-grant-tables
- open another terminal, log in as su privileges than, log in mysql without password
mysql -u root
- change the password
UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
- flush privileges
FLUSH PRIVILEGES;
- You are done now
The Answer 10
5 people think this answer is useful
The methods mentioned in existing answers don’t work for mysql 5.7.6 or later. According mysql documentation this is the recommended way.
B.5.3.2.3 Resetting the Root Password: Generic Instructions
MySQL 5.7.6 and later:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Reference: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
The Answer 11
3 people think this answer is useful
If you can’t remember your password, @radtek’s answer worked for me except in my case I had set up MySQL using brew which meant that steps 1 and 2 of his answer had to be changed to:
/usr/local/bin/mysql.server stop
/usr/local/bin/mysqld_safe --skip-grant-tables
Note: the lack of sudo
.
The Answer 12
3 people think this answer is useful
I think this should work :
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD'
(Note that you should probably replace root with your username if it isn’t root)
The Answer 13
2 people think this answer is useful
Stopping MySQL Server
sudo /usr/local/mysql/support-files/mysql.server stop
Starting MySQL in safe mode
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
Changing the root password
/usr/local/mysql/bin/mysql -u root
use mysql;
UPDATE user SET authentication_string=PASSWORD('NEW_PASSWORD') WHERE user='root';
FLUSH PRIVILEGES;
exit
Testing
Run /usr/local/mysql/bin/mysql -u root
Now enter the new password to start using MySQL.
The Answer 14
2 people think this answer is useful
This is what exactly worked for me:
Make sure no other MySQL process is running.To check this do the
following:
a.From the terminal, run this command:
lsof -i:3306
If any PID is returned, kill it using kill -9 PID
b. Go To System Preferences > MySQL > check if any MySQL instances
are running, stop them.
Start MySQL with the command:
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
The password for every user is stored in the mysql.user table under
columns User and authentication_string respectively. We can update the
table as:
UPDATE mysql.user SET authentication_string='your_password' where User='root'
The Answer 15
2 people think this answer is useful
macOS 10.14+ with 5.7.26 installed from Mac OSX DMG installer.
When attempting to use the UPDATE command posted by other users results in the following error:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Copy the password that was presented to you by the Installer open terminal and do the following:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURPASSWORDHERE';
The Answer 16
2 people think this answer is useful
Try this in terminal :
/usr/local/bin/mysql_secure_installation
The Answer 17
2 people think this answer is useful
Let us add this workaround that works on my laptop!
Mac with Osx Mojave 10.14.5
Mysql 8.0.17 was installed with homebrew
I run the following command to locate the path of mysql
brew info mysql
Once the path is known, I run this :
/usr/local/Cellar/mysql/8.0.17/bin/mysqld_safe --skip-grant-table
In another terminal I run :
mysql -u root
Inside that terminal, I changed the root password using :
update mysql.user set authentication_string='NewPassword' where user='root';
and to finish I run :
FLUSH PRIVILEGES;
And voila the password was reset.
References :
The Answer 18
2 people think this answer is useful
You can manually turn-off mysql on Mac, by clicking on  Apple menu and open System Preferences. Choose the “MySQL” preference panel, then click on the “Stop MySQL Server” button to stop MySQL Server on Mac.
After you stop your mysql you’ll need to follow these steps.
- You’ll need to start mysql in skip-grant-tables mode
$ sudo /usr/local/mysql/support-files/mysql.server start –skip-grant-tables
- In your terminal itself, enter this command to FLUSH existing PRIVILEGES
/usr/local/mysql/bin/mysql mysql> FLUSH PRIVILEGES;
- Now you need to alter the user password
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘newpassword’;
mysql> exit
Then you can go to  Apple menu and open System Preferences. Choose the “MySQL” preference panel, then click on the “Stop MySQL Server” button to stop MySQL Server on Mac.
Finally you can again go to  Apple menu and open System Preferences. Choose the “MySQL” preference panel, then click on the “Start MySQL Server” button to start MySQL Server on Mac.
Hope that helps
The Answer 19
2 people think this answer is useful
None of the previous comments solve the issue on my Mac.
I used the commands below and it worked.
$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -u root
The Answer 20
1 people think this answer is useful
If you forgot your password or want to change it to your mysql:
- start your terminal and enter:
sudo su
- Enter pass for you system
- Stop your mysql:
sudo /usr/local/mysql/support-files/mysql.server stop
- Leave this window OPEN, run second terminal window and enter here:
mysql -u root
- And change your password for mysql:
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
where “new_password” – your new pass. You don’t need old pass for mysql.
- Flush, quit and check your new pass:
FLUSH PRIVILEGES;
- Close all windows and check your new pass for mysql.
Good luck.
The Answer 21
1 people think this answer is useful
Much has changed for MySQL 8. I’ve found the following modification of the MySQL 8.0 “How to Reset the Root Password” documentation works with Mac OS X.
Create a temp file $HOME/mysql.root.txt
with the SQL to update the root password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<new-password>';
This uses mysql_native_password
to avoid the Authentication plugin ‘caching_sha2_password’ cannot be loaded error, which I get if I omit the option.
Stop the server, start with an --init-file
option to set the root password, then restart the server:
mysql.server stop
mysql.server start --init-file=$HOME/mysql.root.txt
mysql.server stop
mysql.server start
The Answer 22
1 people think this answer is useful
To reference MySQL 8.0.15 + , the password() function is not available. Use the command below.
Kindly use
UPDATE mysql.user SET authentication_string='password' WHERE User='root';
The Answer 23
1 people think this answer is useful
I solved this by:
- Shutting down my MySQL server:
mysql.server stop
- Running MySQL in safe mode:
mysqld_safe --skip-grant-tables
- In another terminal, login with
mysql -u root
- In the same terminal, run
UPDATE mysql.user SET authentication_string=null WHERE User='root';
, then FLUSH PRIVILEGES;
and then exit with exit;
- Stop the safe mode server with
mysql.server stop
and then start the normal one; mysql.server start
Now you can set your new password with
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
The Answer 24
0 people think this answer is useful
mysqld_safe --skip-grant-tables
mysql -u root
UPDATE mysql.user SET authentication_string='yourpasswd' WHERE User='root';
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
I somehow need to do this every time my Macbook restarts. Posting this for personal reference, hopefully it helps someone else as well.