如何设置mysql root密码:





1、首次安装 root初始密码为空,注意就是没有密码,直接敲回车即可进入

D:\wamp\bin\mysql\mysql5.6.17\bin>
mysql -uroot -p

Enter password:  [直接回车]

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.6.17 MySQL Community Server (GPL)





Copyright (c) 2000, 2014, 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>





2、修改root密码的几种方法:

1) 用SET PASSWORD命令

  首先登录MySQL。

  格式:mysql> set password for 用户名@localhost = password('新密码');

  例如:

mysql>
set password for root@localhost = password('root');

Query OK, 0 rows affected (0.00 sec)





mysql>
quit

Bye





D:\wamp\bin\mysql\mysql5.6.17\bin>
mysql -uroot -proot

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 8

Server version: 5.6.17 MySQL Community Server (GPL)





Copyright (c) 2000, 2014, 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> 





2)用mysqladmin

  格式:mysqladmin -u用户名 -p旧密码 password 新密码

  例如:

D:\wamp\bin\mysql\mysql5.6.17\bin>
mysqladmin -uroot -proot password root123

Warning: Using a password on the command line interface can be insecure.





D:\wamp\bin\mysql\mysql5.6.17\bin>
mysql -uroot -proot123

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 10

Server version: 5.6.17 MySQL Community Server (GPL)





Copyright (c) 2000, 2014, 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>





3)用UPDATE直接编辑user表

  首先登录MySQL。

  
mysql> use mysql;
  mysql> update user set password=password('root') where user='root' and host='localhost';
  mysql> flush privileges;


--注意一定要flush privileges;

mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。





4)在忘记root密码的时候,可以这样。

  以windows为例:

  1. 关闭正在运行的MySQL服务。

  2. 打开DOS窗口,转到mysql\bin目录。

  3. 输入mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。

  4. 再开一个DOS窗口(因为刚才那个DOS窗口已经不能动了),转到mysql\bin目录。

  5. 输入mysql回车,如果成功,将出现MySQL提示符 >。

  6. 连接权限数据库: use mysql; 。

  6. 改密码:update user set password=password('root123') where user='root';(别忘了最后加分号) 。

  7. 刷新权限(必须步骤):
flush privileges; 

  8. 退出quit当前cmd,并且关闭2中的DOS窗口

  9. 使用用户名root,新密码root123在4中DOS窗口登录。

-----------------------------

Dylan    Presents.

如何设置mysql root密码的更多相关文章

  1. mysql设置更改root密码、mysql服务器的连接、mysql常用命令

     1.设置更改root密码 查看mysql 启动与否,若没启动就运行:/usr/local/mysql56/bin/mysqlps aux |grep mysql  或 netstat -tulnp ...

  2. 设置更改root密码、连接mysql、mysql常用命令

    6月19日任务 13.1 设置更改root密码13.2 连接mysql13.3 mysql常用命令 13.1 设置更改root密码 使用场景:例如长时间不用忘记了mysql的root密码,那么就需要去 ...

  3. Linux centosVMware MySQL常用操作设置更改root密码、连接mysql、mysql常用命令

    一.设置更改root密码 启动mysql /usr/local/mysql/bin/mysql -uroot 更改环境变量PATH,增加mysql绝对路径 使mysql -uroot永久生效需要编辑, ...

  4. 几种破解MySQL root密码的几种方法:

    几种破解MySQL root密码的几种方法: 方法一 使用phpmyadmin,这是最简单的了,修改mysql库的user表,不过别忘了使用PASSWord函数. 方法二 使用mysqladmin,这 ...

  5. 使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失(转)

    B.5.3.2 How to Reset the Root Password If you have never assigned a root password for MySQL, the ser ...

  6. 不重启修改mysql root密码

    不重启修改mysql root密码 --------------------2014/09/28 一.一般忘记密码的解决办法,需要重启Mysql1.skip-grant-tables我们常用的方法是使 ...

  7. MySQL root密码忘记解决

    --MySQL root密码忘记的解决办法 -----------------------------------2014/03/14 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接My ...

  8. MySQL root密码忘记,原来还有更优雅的解法!

    一直以来,对于MySQL root密码的忘记,以为只有一种解法-skip-grant-tables. 问了下群里的大咖,第一反应也是skip-grant-tables.通过搜索引擎简单搜索了下,无论是 ...

  9. 修改MySql Root密码(包含忘记密码的方式)

    曾几何时,我也是记得MySQL root密码的人,想要修改root密码还不是轻而易举的事?下面前三种修改改方式都是在记得密码的情况下进行修改,如果你忘记了原本的root,请直接跳至 终极 第一种: 在 ...

  10. 修改mysql root密码,在workbench中导入.sql文件

    修改mysql root密码: 1.如果没有配置环境变量,在 \Program Files\MySQL\MySQL Server 8.0\bin 文件下 Shit+右键打开 Powershell 窗口 ...

随机推荐

  1. [转帖]SQL Server 2008~2022版本序列号/密钥/激活码 汇总

    https://www.cnblogs.com/cqpanda/p/16148822.html SQL Server 2022# Enterprise: J4V48-P8MM4-9N3J9-HD97X ...

  2. [转帖]金仓数据库KWR使用说明

    金仓数据库KWR使用说明 1.KWR性能报告介绍 2.部署KWR性能报告功能 2.1.修改配置文件 2.2.使配置文件中参数生效 2.3.创建KWR扩展 3.使用KWR快照功能 3.1.创建KWR快照 ...

  3. [转帖]VMware Workstation PRO 17.0.2正式版+激活密钥

    https://www.isharepc.com/36181.html VMware Workstation PRO 17是一个简化的桌面虚拟化应用程序. 它在同一台计算机上运行一个或多个操作系统而无 ...

  4. [转帖]oracle OSWatcher安装部署

    Oswatch是oracle官方提供,用于收集操作系统性能的小工具,oswatch的安装与使用也比较简单,直接解压就可以使用.oswatch是通过调用系统的命令完成信息的收集,如:ps ,top ,m ...

  5. 关于sar的学习

    关于sar的学习 背景 公司一套基于某冷门Python架构的系统前几天出现异常卡顿. 当时安装的时候必须使用ubuntu系统. 所以当时默认安装的ubuntu1804, 本来想尝试使用一下sar查看卡 ...

  6. [转帖]10--k8s之数据持久化

    https://www.cnblogs.com/caodan01/p/15136217.html 目录 一.emptDir 二.hostPath 三.pv 和 pvc 1.环境准备 2.创建pv 3. ...

  7. [转帖]Shell~echo -e 颜色输出

    https://www.cnblogs.com/ElegantSmile/p/11144879.html echo -e 可以控制字体颜色和背景颜色输出 从一个例子开始: # echo -e &quo ...

  8. 容器方式运行Mysql8.0.26的方法

    容器化运行Mysql8.0.26测试环境的方法 1. 前言 之前为了好处理,都是二进制包的方式安装mysql,但是有时候需要下载和安装也比较费时费力, 今天中午在弄Oracle RAC时想着以后能够容 ...

  9. clickhouse 优化实践,万级别QPS数据毫秒写入和亿级别数据秒级返回 | 京东云技术团队

    1.背景 魔笛活动平台目前在采集每个活动的用户行为数据并进行查询,解决线上问题定位慢,响应不及时的问题,提升客诉的解决效率.目前每天采集的数据量5000万+,一个月的数据总量15亿+,总数据量40亿+ ...

  10. 【分享一个工具】根据 /metrics 路径下的文本信息,自动生成包含所有 metrics 的 grafana 报表

    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 在做某个服务对应的 grafana 监控报表的时候发现,一 ...