美文网首页
MYSQL root 密码重置

MYSQL root 密码重置

作者: wsf535 | 来源:发表于2018-02-14 16:13 被阅读5次

    MAC电脑
    停止正在运行的mysqlserver服务




    打开命令行进入特权模式

    #在提示后输入密码
    sudo su
    #进入mysql目录
    cd /usr/local/mysql/bin/
    #进安全模式
    ./mysqld_safe --skip-grant-tables &
    #回车后mysql会自动运行,可以通过下面命令进入mysql
    ./mysql
    #重置密码
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.04 sec)
    mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('password'); #把小写的password改电脑你的新密码
    Query OK, 0 rows affected, 1 warning (0.01 sec)
    mysql> exit
    #结束临时安全模式,重启mysql服务
    sh-3.2# jobs
    [1]+  Running                 ./mysqld_safe --skip-grant-tables &
    sh-3.2# kill %1
    

    重启后就可以用 root 与password进mysql了

    wsf535deMacBook-Air:bin wsf535$ mysql -uroot -ppassword
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 231
    Server version: 8.0.3-rc-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2017, 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> 
    

    mysql安装完提示 -bash: mysql: command not found 需加以下环境变量。
    (1)vi ~/.bash_profile;
    (2)添加 export PATH=$PATH:/usr/local/mysql/bin;
    (3)保存退出;
    (4)source ~/.bash_profile;

    相关文章

      网友评论

          本文标题:MYSQL root 密码重置

          本文链接:https://www.haomeiwen.com/subject/owuetftx.html