mac mysql忘记密码

今天想升级到 8.0,以前安装的 5.7 版,几年不用,密码早就忘记了,几年前曾经处理过,重新来过,重新记录一次

Mac mysql 忘记 root 密码

  1. 停止 mysql

    $ mysql -V

     mysql  Ver 14.14 Distrib 5.7.21, for macos10.13 (x86_64) using  EditLine wrapper
    

    $ ps -ef |grep mysql

    $ sudo pkill mysql

  2. 查找mysql 在哪里

    $ which mysql

     /usr/local/mysql/bin/mysql
    
  3. 进入 mysql 目录

    cd /usr/local/mysql/bin/

    $ ls mysql*

    可以看到,mysql 的这些命令都在这里

     mysql				mysql_tzinfo_to_sql		mysqldump
     mysql_client_test_embedded	mysql_upgrade			mysqldumpslow
     mysql_config			mysqladmin			mysqlimport
     mysql_config_editor		mysqlbinlog			mysqlpump
     mysql_embedded			mysqlcheck			mysqlshow
     mysql_install_db		mysqld				mysqlslap
     mysql_plugin			mysqld-debug			mysqltest_embedded
     mysql_secure_installation	mysqld_multi			mysqlxtest
     mysql_ssl_rsa_setup		mysqld_safe
     dhbm-on-mac20180816:bin dhbm$ 
    
  4. 进入 su

    $ sudo su

     sh-3.2#
    
  5. 禁止mysql验证功能

    一定要 cd /usr/local/mysql/bin/ ,否则会报错 ./mysqld_safe: No such file or directory

    sh-3.2# ./mysqld_safe --skip-grant-tables &

     [1] 4297
     sh-3.2# 2023-03-24T01:16:50.6NZ mysqld_safe Logging to '/usr/local/mysql-5.7.21-macos10.13-x86_64/data/dhbm-on-mac20180816.local.err'.
     2023-03-24T01:16:50.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.21-macos10.13-x86_64/data
    
  6. 启动 mysql

    sh-3.2# ./mysql

     Welcome to the MySQL monitor.  Commands end with ; or \g.
     Your MySQL connection id is 2
     Server version: 5.7.21 MySQL Community Server (GPL)
     
     Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
     
     Oracle is a registered trademark of Oracle Corporation and/or its
     affiliates. Other names may be trademarks of their respective
     owners.
     
     Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
     
     mysql> 
    
  7. 重设密码

    mysql> FLUSH PRIVILEGES;

    语法总是错误,先 HELP ,从 HELP 的例子抄写一个

    mysql> help SET PASSWORD

    mysql> SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(‘Password@123’);

    mysql> exit

    sh-3.2# exit

  8. $ mysql -u root -p

    使用新密码,OK !

你可能感兴趣的:(mysql,macos,数据库)