MacOSX homebrew mysql root password

前端 未结 21 1651
自闭症患者
自闭症患者 2020-12-04 05:43

For some reason MySQL stopped giving access for root. Uninstalled and reinstalled with Homebrew. Fresh install, fresh tables but when I enter

mysql -u root -         


        
21条回答
  •  囚心锁ツ
    2020-12-04 06:20

    Since the question was asked/answered long time ago, those top answers do not work for me. Here's my solution, in 2020.

    Background: Fresh mysql/mariadb installed by homebrew.

    Problem: The password for root is not empty and unknown.

    The fix:

    1. mysql -u YOUR-SYSTEM-USERNAME -p
    2. The password is empty (press enter)
    3. ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW-ROOT-PASSWORD';
    4. FLUSH PRIVILEGES;

    The reason:

    1. Homebrew will create a user with root privileges named by the current MacOS username.
    2. it has no password
    3. Since it has all privileges, just reset the root password with that user.
    4. The initial password for root was randomly generated.

提交回复
热议问题