I am trying to set the root password for MySQL in the terminal in Mac OS X Lion, and I am having issues. Every time I use the line:
/usr/local/mysql/bin/mysqladmin -u root password ****** (where ****** is the password I want to set)
I receive the error:
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
I have not set a password previously, so I do not know why I am receiving this error.
Here is the procedure to reset password of root user.
1) Stop mysql (Kill mysql process or run following command)
sudo /usr/local/mysql/support-files/mysql.server stop
2) Start it in safe mode
sudo mysqld_safe --skip-grant-tables
3) Open another terminal and run the following command (Keep last terminal open)
mysql -u root
4) Run the following command with suitable new password on the mysql console
For MySQL 5.7+:
mysql > UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
For earlier versions:
mysql > UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
5) mysql > FLUSH PRIVILEGES;
6) Quit from both terminals and open new terminal and connect to mysql with root user and new password
mysql -uroot -p
Type:/usr/local/mysql/bin/mysqladmin -u root -p password
When it asks for a password, not not enter anything, just hit enter. It will then ask you to enter new password, then confirm. Finished.
for creating password first time use
mysqladmin -u root password NEWPASSWORD
updating old password use
mysqladmin -u root -p'oldpassword' password newpass
Source = http://www.cyberciti.biz/faq/mysql-change-root-password/
I'm on Yosemite, but on Maverick has the same problem. - Fix the 2002 socket error first if you haven’t done
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
An then try
sudo /usr/local/mysql/bin/mysqladmin -u root -p password
That isn't how you set the password. That is how you login to mysql.
If you don't have a password set, you login using:
mysql -u root
and that will get you to the MySQL command line.
Instead of doing that just use the following to change the password.
mysqladmin -u root password NEWPASSWORD
cd /usr/local/mysql/bin
./mysqladmin -u root password root
To set your root password after installing:
- Ensure MySQL is not running, stop it if you ran it.
- On a Terminal do
sudo mysqld_safe --skip-grant-tables
to run MySQL bypassing the authentication. - Inside mysql do
FLUSH PRIVILEGES;
- Then reset by
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
where 'password' is your chosen password. FLUSH PRIVILEGES;
one more time
This fix it for me: After this is going to ask you for your Super User password and then for the new password.
sudo /usr/local/mysql/bin/mysqladmin -u root -p password
You want to reset or set a new root password?
Steps for MySQL 5.7.5 and earlier:
Open a Terminal Window:
Stop mysql server if it is running:
sudo /usr/local/mysql/support-files/mysql.server stop
Restart it with the
--skip-grant-tables
option:sudo mysqld_safe --skip-grant-tables
Open another Terminal Window:
Type:
mysql -u root
Reset root password (i.e. for localhost)
UPDATE mysql.user SET authentication_string = PASSWORD(‘MyNewPass’), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost'; FLUSH PRIVILEGES;
Now your password for root@localhost is MyNewPass. You can change it:
Close all Terminal Windows. Open a new Terminal Window and type:
mysqladmin -u root -p'MyNewPass' password '123456'
Now your root password is 123456
You should see below warning message, you can ignore it if you are changing your root@localhost password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
Check if your root password is successfully changed:
mysql -u root -p'123456' -e 'show databases;'
Output:
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
This is working on macOS Sierra
step 1: open terminal
step 2: paste the following command
sudo /usr/local/mysql/support-files/mysql.server restart
Your terminal should show this :
Users-MacBook-Air:~ usr$ sudo /usr/local/mysql/support-files/mysql.server restart
Password: ERROR! MySQL server PID file could not be found!
Starting MySQL .. SUCCESS!
Step 3: Make sure SQL server is running
Step 4: Open the MYSQL working and click the local instance
Step 5: type old password and new password
You will lose all databases
step 1: open terminal
step 2: delete folder mysql
sudo rm -rf /usr/local/mysql
step 3: installed mysql again, after the installation is generated a new password
Step 1:
mysql -u root -p
It will ask Enter password:
Welcome to the MySQL monitor.
You can check default databases
mysql> show databases;
mysql> show tables;
来源:https://stackoverflow.com/questions/8541115/mysql-password-issues-mac-os-x-lion