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?
I think this should work :
(Note that you should probably replace root with your username if it isn't root)
This is what exactly worked for me:
Make sure no other MySQL process is running.To check this do the following:
Start MySQL with the command:
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:
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
(2) Start it in safe mode:
(3) This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
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
(5) Start MySQL
If you don't remember the password you set for root and need to reset it, follow these steps:
sudo mysqld_safe --skip-grant-tables;
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
If you forgot your password or want to change it to your mysql:
where "new_password" - your new pass. You don't need old pass for mysql.
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 terminalChange out NEWPASSWORD with whatever password you want. Should be all set!
Update: As of MySQL 5.7, the
password
field has been renamedauthentication_string
. When changing the password, use the following query to change the password. All other commands remain the same: