MySQL 帐户名与密码修改!

Mac系统:

由于日常进数据库时都是记住密码,大家懂得!html

目前网上对于修改数据库用户名和密码的方法太多了,如下为我尝试且成功的一种:mysql

NidhoggDJokingdeMacBook-Pro:~ joking$ cd /usr/local/mysql/bin/ 
NidhoggDJokingdeMacBook-Pro:bin joking$ ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> 复制代码


PS:根据 MySQL 版本的不一样,执行命令:sql

最开始没注意有这个问题,仍是补充一下。数据库

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');
复制代码

  这里是官方的文献资料!
bash


Windows环境下:

不管在那个环境下切记最早关闭数据库的服务!


  • DOS命令 net stop mysql

  • 转到mysqlbin目录

  • 能够经过打开mysql应用快速找到mysqlbin目录

  • 复制路径而后在DOS里输入cd空格贴路径

  • 输入mysqld --skip-grant-tables回车。

  • 若是没有出现提示信息,那就对了再开一个DOS窗口(刚才那个DOS窗口已经不能动了),

  • 转到mysqlbin目录输入mysql回车,若是成功,将出现MySQL提示符 >

  • 输入FLUSH PRIVILEGES;(带分号)

  • 输入SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234');

  • 重启服务net start mysql


Mysql程序在D盘:ui

C:\Users\Administrator>cd..

C:\Users>cd..

C:\>d:

D:\>
复制代码

在进入mysql文件夹的bin目录spa

相关文章
相关标签/搜索