MySQL password issues (mac OS X Lion) [closed]

≯℡__Kan透↙ 提交于 2019-11-29 21:35:39
minhas23

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
Huge

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:

  1. Ensure MySQL is not running, stop it if you ran it.
  2. On a Terminal do sudo mysqld_safe --skip-grant-tables to run MySQL bypassing the authentication.
  3. Inside mysql do FLUSH PRIVILEGES;
  4. Then reset by SET PASSWORD FOR root@'localhost' = PASSWORD('password'); where 'password' is your chosen password.
  5. 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:

  1. Stop mysql server if it is running:

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

  2. Restart it with the --skip-grant-tables option:

    sudo mysqld_safe --skip-grant-tables

Open another Terminal Window:

  1. Type: mysql -u root

  2. 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:

  1. 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.

  2. 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

user10798253

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;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!