mysql linux改密码忘记了怎么办_linux上mysql改密码忘了怎么办?
解决方法:1、在my.cnf中,增加“[mysqld]”和“skip-grant-tables”2行代码,用于登录时跳过密码验证;2、启动mysql服务,并登录mysql;3、连接mysql数据库,使用UPDATE命令修改用户密码即可。
linux上mysql改密码忘了的解决方法
修改密码
1. 检查mysql服务是否启动,如果启动,关闭mysql服务//查看mysql服务状态
[root@mytestlnx02 ~]# ps -ef | grep -i mysql
root 22972 1 0 14:18 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 23166 22972 0 14:18 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 23237 21825 0 14:22 pts/0 00:00:00 grep -i mysql
//关闭服务
[root@mytestlnx02 ~]# service mysql stop
[root@mytestlnx02 ~]#
2. 修改mysql的配置文件my.cnf
my.cnf配置文件的位置,一般在/etc/my.cnf,有些版本在/etc/mysql/my.cnf
在配置文件中,增加2行代码[mysqld]
skip-grant-tables
作用是登录mysql的时候跳过密码验证
然后启动mysql服务,并进入mysql[root@mytestlnx02 ~]# service mysqld start
[root@mytestlnx02 ~]#
[root@mytestlnx02 ~]# mysql -u root
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
3. 修改密码
连接mysql这个数据库,修改用户密码mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update mysql.user set authentication_string=password('root_password') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
4. 重启mysql服务
先将之前加在配置文件里面的2句代码注释或删除掉,然后重启mysql服务,就可以使用刚刚设置的密码登录了。[root@mytestlnx02 ~]# service mysql start
[root@mytestlnx02 ~]#
[root@mytestlnx02 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
p.s.
在CentOS上的操作方式有所不同。
执行修改密码的命令一直报错mysql> update user set authentication_string=password('xxxxxxxx') where User='root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('root_password') where User='root'' at line 1
不可能是语法问题,检查了很多遍,最后发现CentOS下应该这样操作:
查看初始密码[root@VM_0_8_centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-09-26T04:25:54.927944Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: DN34N/=?aIfZ
可以看到初始密码为DN34N/=?aIfZ
使用初始密码登录[root@VM_0_8_centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
修改密码mysql> ALTER USER 'root' IDENTIFIED BY 'xxxxxxxxx';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxxx';
Query OK, 0 rows affected (0.11 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
重启服务就生效了[root@VM_0_8_centos ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
[root@VM_0_8_centos ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
mysql linux改密码忘记了怎么办_linux上mysql改密码忘了怎么办?相关推荐
- linux系统mysql密码忘记了怎么办_Linux中MySQL密码忘了怎么办
Linux中MySQL密码忘了怎么办 1.首先编辑/etc/my.cnf文件vim /etc/my.cnf 在文件中加入一行配置skip-grant-tables 例如加到这个位置# read_rnd ...
- linux系统mysql密码忘记了怎么办_Linux系统下忘记MySql密码怎么办
匿名用户 1级 2016-06-19 回答 如果不是root密码:用root进去,修改mysql数据库user表咯. 如果是root密码: 方法一: MySQL提供跳过访问控制的命令行参数,通过在命令 ...
- openstack登陆密码忘记?如何重置dashboard界面登陆密码
用RDO方法安装openstack登陆密码忘记?如何重置dashboard界面登陆密码 利用token来进行管理用户,自己写一个变量文件 vim xljd_rc export OS_TOKEN=xxx ...
- linux mysql 密码_Linux上mysql修改密码的几种方法和mysql忘记密码的修改方式
方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass ...
- mysql root密码忘记2018_2018-03-28设置及修改mysql用户密码学习笔记
退出mysql方法 quit或者exit 设置及修改mysqlroot用户密码 安装mysql后,默认管理员root密码为空,这很不安全,需要设置一个密码,在安装mysql单实例后,有个初始优化的一些 ...
- 查询电脑上mysql的密码忘记了怎么办_windows下mysql忘记root密码的解决方法 -电脑资料...
方法一: 1.在DOS窗口下输入net stop mysql5 或 net stop mysql 2.开一个DOS窗口,这个需要切换到mysql的bin目录, 一般在bin目录里面创建一个批处理1.b ...
- 网站需要服务器密码登录密码忘记了怎么办,云服务器登录需要密码忘记了怎么办...
云服务器登录需要密码忘记了怎么办 内容精选 换一换 如果在创建云服务器时未设置密码,或密码丢失.过期,可以通过控制台提供的" 重置密码 " 功能设置新密码.重置密码:选中待重置密码 ...
- 浏览器网站密码忘记了、xshell里面的服务器密码忘记了
声明:本文乃"运维家"原创,转载请注明出处,更多内容请关注公众号"运维家". PS:本文章仅供个人在属于自己的资源且正确的情况下进行使用,请合法使用,禁止进行非 ...
- mysql linux 中文乱码怎么解决_如何解决mysql linux 中文乱码的问题
解决mysql linux中文乱码的方法: 1.查看mysql的默认字符集#mysql -u root - p #(输入密码) mysql> show variables like 'chara ...
最新文章
- 微型计算机字长是不是字节的倍数,2014台湾省WORD全国计算机等级考试二级VB考试技巧重点...
- 多线程python 客户端fuwuq实现方式_python实现二叉树数据结构的多种遍历方式
- [vue] 你了解axios的原理吗?有看过它的源码吗?
- 前端为什么说github很重要_私域流量|为什么说私域流量很重要?
- MySQL提示The server quit without updating PID file问题的解决办法
- ecology9 系统文件常用说明
- centos虚拟机克隆
- dotween路径移动_使用DOTween Pro插件设置物体移动的位置、移动的方式、以及动画结束时执行方法...
- linux下载和安装activemq
- 3.对于python的一个非正式导言 编译之三
- 天啦撸,联合开发网竟然倒闭了!!!(分享一个非常牛的人工智能教程!!!)
- SCSI子系统基础学习笔记 (之UFS子系统) - 1.2 概述(软件部分)
- 把手机摄像头或智能电视摄像头数据推送到另一台手机或智能电视上的方法
- 考研英语 - word-list-19
- 大体重程序员的减肥经历(不完整待补充)
- OSChina 周六乱弹 ——你们怎么懂我的少年心
- Matplotlib 学习之:给图片 / 图片的子图添加颜色条/渐变条(colorbar)
- 乌班图服务器清理log文件,定时清除ubuntu下log日志文件
- 2022建筑电工(建筑特殊工种)复训题库及答案
- Java--创建窗口和程序片
热门文章
- 学习antd-design-pro
- 计算机应用基础第二章,计算机应用基础第二章上机操作题
- 在正式使用计算机账务系统的银行对账功能,用友ERP-U8管理系统认证考试理论题...
- 读芯术python教程答案_攻略Python的免费书单:走进编程,从这五本书开始
- 制作 mysql的rpm文件_自制mysql.rpm安装包
- IE浏览器开发人员工具怎么使用
- 手把手教你dns服务器未响应导致无法上网怎么办
- win8升级win10出现错误代码1049怎么回事
- springboot如何使用log4j记录日志
- springboot基于mybatis扫描jar包中的controller、service、dao、xml