Markdown

[MySQL] mac 中 mysql 登入失敗

mysql mac

  1. Stop the mysqld server. Typically this can be done by from ‘System Prefrences’ > MySQL > ‘Stop MySQL Server’
  2. Start the server in safe mode with privilege bypass
    From a terminal:
    sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
  3. In a new terminal window:
    sudo /usr/local/mysql/bin/mysql -u root
    UPDATE mysql.user SET Password=PASSWORD(‘NewPassword’) WHERE User=‘root’;
    FLUSH PRIVILEGES;
    \q
  4. Stop the mysqld server again and restart it in normal mode.
到了第三步會出現問題:
ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’
改成
update MySQL.user set authentication_string=password(‘root’) where user=‘root’ ;
就可以更改成功了
之後退出安全模式
重新登入

重新登入就可以了 不過 直接輸入mysql 登入會出現找不到命令
要把mysql 加到環境命令中
mysql command not found
.bash_profile
export PATH=${PATH}:/usr/local/mysql/bin

留言