mysql重置密码

参考:mysql 官方重置密码

  1. 杀掉mysql进程
1
2
# shell> kill `cat /mysql-data-directory/host_name.pid`
sudo kill `sudo cat /usr/local/mysql/data/localhost.pid`
  1. 重写init.sql

  2. 1
    2
    3
    4
    --MySQL 5.7.6 and later:
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    --MySQL 5.7.5 and earlier:
    --SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

    用mysql-init启动mysql

    1
    2
    # mysqld --init-file=/initFilePath &
    shell> sudo mysqld --init-file=/Users/lineworks/Documents/utilities/mysql/mysql-init &