设置用户密码

方法一

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NewPassword');

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
Query OK, 0 rows affected (0.00 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> \q
Bye
[root@node ~]# mysql -uroot -p123456
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 5
Server version: 5.6.39 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>

方法二

UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

mysql> UPDATE mysql.user SET Password = PASSWORD('234567') WHERE user = 'root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> \q
Bye
# 这里使用新密码登陆
[root@node ~]# mysql -uroot -p234567
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 16
Server version: 5.6.39 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>

丢失root密码找回

两种方式:

  1. 在启动的时候增加 --skip-grant-tables 参数启动
  2. my.cnf配置文件中的mysql模块中添加下面参数 skip-grant-tables = 1

上面两种方式效果相同

使用后,启动mysql,就可以使直接使用mysql 命令登陆,无需密码,进入后直接修改root密码即可,最后去掉参数或者配置文件中的参数重启数据库即可;

添加用户

运维常用 MySQL 命令的更多相关文章

  1. Hadoop集群-HDFS集群中大数据运维常用的命令总结

    Hadoop集群-HDFS集群中大数据运维常用的命令总结 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客会简单涉及到滚动编辑,融合镜像文件,目录的空间配额等运维操作简介.话 ...

  2. 整理一些Windows桌面运维常用的命令,并且整合成脚本

    github地址:alittlemc/toy: 编写些脚本将运维经常所用到小玩意所集成在一起 (github.com) 持续更新! 前言 做过桌面运维的大佬们应该可以很明显感受到这份工作所需要的技能不 ...

  3. 运维常用mysql语句

    1..select @@version; ##查询当前mysql的版本. 2. show variables like 'port';##查看mysql实例的端口. 3.show variables ...

  4. Linux运维常用的命令详解

    1. 查看系统内核版本 [root@funsion geekxa]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m 显示了系 ...

  5. linux学习13 Linux运维常用文件管理命令及系统变量基础

    一.文件管理命令 1.cp命令,copy a.单源复制,cp [OPTION]... [-T] SOURCE DEST 如果DEST不存在:则事先创建此文件,并复制源文件的数据流至DEST中. 如果D ...

  6. centos 7 查看系统/硬件信息及运维常用命令+联想Y430P无线网卡驱动安装

     centos 7 查看系统/硬件信息及运维常用命令 当前环境:联想Y430P  CentOS 7.3 [root@yan-001 ~] # uname -a # 查看内核/操作系统/CPU信息的Li ...

  7. 提高Linux运维效率的命令行常用快捷键

    提高Linux运维效率的命令行常用快捷键 tab 命令或路径等的补全键,Linux最有用快捷键 Ctrl+a 光标回到命令行首 Ctrl+e 光标回到命令行尾 Ctrl+k 剪切(删除)光标处到行尾的 ...

  8. Linux运维常用150个命令

    Linux运维常用150个命令 转载自:www.cnblogs.com/bananaaa/p/7774467.html 命令 功能说明 线上查询及帮助命令(2个) man 查看命令帮助,命令的词典,更 ...

  9. Linux运维常用的几个命令介绍【转】

    Linux运维常用的几个命令介绍 1. 查看系统内核版本​ [root@funsion geekxa]# cat /etc/issue CentOS release 6.5 (Final) Kerne ...

随机推荐

  1. "Dependency on app with no migrations: %s" % key[0]

    问题描述:我在model中建好模型类,运行的控制台就报错误: 解决方法:1,首先需要在setting中重载AUTH_USER_MODEL AUTH_USER_MODEL = 'users.UserPr ...

  2. linux centos ubutun svn搭建

    1.卸载SVN 查看自己是否安装了svn svn 上图显示已安装,可用以下命令进行卸载 sudo apt-get remove --purge subversion (–purge 选项表示彻底删除改 ...

  3. 【并发编程】Volatile原理和使用场景解析

    目录 一个简单列子 Java内存模型 缓存不一致问题 并发编程中的"三性" 使用volatile来解决共享变量可见性 volatile和指令重排(有序性) volatile和原子性 ...

  4. Splash API 调用

    render.html render.html 接口用于获取 JavaScript 渲染的页面的 HTML 代码,接口地址就是 Splash 的运行地址加此接口名称,例如http://localhos ...

  5. [翻译]——MySQL 8.0 Histograms

    前言: 本文是对这篇博客MySQL 8.0 Histograms的翻译,翻译如有不当的地方,敬请谅解,请尊重原创和翻译劳动成果,转载的时候请注明出处.谢谢! 英文原文地址:https://lefred ...

  6. 天天玩微信,Spring Boot 开发私有即时通信系统了解一下

    1/ 概述 利用Spring Boot作为基础框架,Spring Security作为安全框架,WebSocket作为通信框架,实现点对点聊天和群聊天. 2/ 所需依赖 Spring Boot 版本 ...

  7. C#之委托如此简单

    近期和几位做嵌入式开发的朋友闲聊过程中,一位朋友抱怨到:这C#太难用了,我想在N个窗体(或者是N个用户组件之间)传递值都搞不定,非得要定义一个全局变量来存储,然后用定时器来刷新值,太Low了.我急切的 ...

  8. salesforce lightning零基础学习(十四) Toast 浅入浅出

    本篇参考: https://developer.salesforce.com/docs/component-library/bundle/force:showToast/specification h ...

  9. 你知道如何优化Join语句吗?

    join语句的两种算法,分别是:NLJ和BNL 测试数据: create table t1(id int primary key, a int, b int, index(a)); create ta ...

  10. 来了!GitHub for mobile 发布!iOS beta 版已来,Android 版即将发布

    北京时间 2019 年 11 月 14 日,在 GitHub Universe 2019大会上,GitHub 正式发布了 GitHub for mobile,支持 iOS 与 Android 两大移动 ...