Mysql学习之--修改root用户口令

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介:

一、拥有原来的myql的root的密码
方法一:
在mysql系统外,使用mysqladmin
mysqladmin -u root -p password "test123"
Enter password: 【输入原来的密码】

方法二:
通过登录mysql系统,
mysql -uroot -p
Enter password: 【输入原来的密码】
mysql>use mysql;
mysql> update user set password=passworD("test") where user='root';
mysql> flush privileges;
mysql> exit;      

二、忘记原来的myql的root的密码:
     首先,你必须要有操作系统的root权限了。要是连系统的root权限都没有的话,先考虑root系统再走下面的步骤。
类似于安全模式登录系统,有人建议说是pkill mysql,但是我不建议哈。因为当你执行了这个命令后,会导致这样的状况:
/etc/init.d/mysqld status
mysqld dead but subsys locked
这样即使你是在安全模式下启动mysql都未必会有用的,所以一般是这样/etc/init.d/mysqld stop,如果你不幸先用了pkill,那么就start一下再stop咯。
mysqld_safe --skip-grant-tables &
&,表示在后台运行,不再后台运行的话,就再打开一个终端咯。
mysql
mysql> use mysql;
mysql> UPDATE user SET password=password("oracle") WHERE user='root';   
mysql> flush privileges;
mysql> exit;      

案例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
[root@ogg ~]# mysqld_safe --skip-grant-tables &
[ 1 3117
[root@ogg ~]#  140924  14 : 03 : 30  mysqld_safe Logging to  '/var/lib/mysql/ogg.err' .
140924  14 : 03 : 30  mysqld_safe A mysqld process already exists
[ 1 ]+  Exit  1                   mysqld_safe --skip-grant-tables
 
关闭mysql server:
[root@ogg ~]# service mysql stop
Shutting down MySQL..                                      [  OK  ]
 
[root@ogg ~]# mysqld_safe --skip-grant-tables &
[ 1 3243
[root@ogg ~]#  140924  14 : 03 : 48  mysqld_safe Logging to  '/var/lib/mysql/ogg.err' .
140924  14 : 03 : 48  mysqld_safe Starting mysqld daemon  with  databases  from  / var /lib/mysql
 
[root@ogg ~]# mysql
Welcome to the MySQL monitor.  Commands end  with  or  \g.
Your MySQL connection id is  1
Server version:  5.1. 47 -log Source distribution
Copyright (c)  2000 2010 , Oracle  and / or  its affiliates. All rights reserved.
This software comes  with  ABSOLUTELY NO WARRANTY. This is free software,
and  you are welcome to modify  and  redistribute it under the GPL v2 license
Type  'help;'  or  '\h'  for  help. Type  '\c'  to clear the current input statement.
mysql> use mysql
Database changed
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4  rows  in  set ( 0.01  sec)
 
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
29  rows  in  set ( 0.00  sec)
 
mysql> update user set password=PASSWORD( 'oracle' where  user= 'root' ;
Query OK,  3  rows affected ( 0.00  sec)
Rows matched:  4   Changed:  3   Warnings:  0
 
mysql> flush privileges;
ERROR  1033  (HY000): Incorrect information  in  file:  './mysql/tables_priv.frm'
 
mysql> exit
Bye
 
[root@ogg ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end  with  or  \g.
Your MySQL connection id is  2
Server version:  5.1. 47 -log Source distribution
Copyright (c)  2000 2010 , Oracle  and / or  its affiliates. All rights reserved.
This software comes  with  ABSOLUTELY NO WARRANTY. This is free software,
and  you are welcome to modify  and  redistribute it under the GPL v2 license
Type  'help;'  or  '\h'  for  help. Type  '\c'  to clear the current input statement.
mysql>

错误信息:   

[root@ogg mysql]# mysqld_safe --skip-grant-tables &

[1] 3795

1
2
3
4
5
6
7
8
9
10
11
12
[root@ogg mysql]#  140924  14 : 15 : 09  mysqld_safe Logging to  '/var/lib/mysql/ogg.err' .
140924  14 : 15 : 09  mysqld_safe Starting mysqld daemon  with  databases  from  / var /lib/mysql
[root@ogg mysql]# mysql
Welcome to the MySQL monitor.  Commands end  with  or  \g.
Your MySQL connection id is  1
Server version:  5.1. 47 -log Source distribution
Copyright (c)  2000 2010 , Oracle  and / or  its affiliates. All rights reserved.
This software comes  with  ABSOLUTELY NO WARRANTY. This is free software,
and  you are welcome to modify  and  redistribute it under the GPL v2 license
Type  'help;'  or  '\h'  for  help. Type  '\c'  to clear the current input statement.
mysql> use mysql
Database changed

mysql> flush privileges;

ERROR 1033 (HY000): Incorrect information in file: './mysql/tables_priv.frm'

mysql> exit

Bye

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@ogg mysql]# service mysql stop
Shutting down MySQL.... .140924  14 : 15 : 44  mysqld_safe mysqld  from  pid file / var /lib/mysql/ogg.pid ended
                                                            [  OK  ]
[ 1 ]+  Done                    mysqld_safe --skip-grant-tables
 
[root@ogg mysql]# service mysql start
Starting MySQL..     
                                       [  OK  ]
                                       
正常连接:                                      
[root@ogg mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end  with  or  \g.
Your MySQL connection id is  1
Server version:  5.6. 4 -m7-log Source distribution
Copyright (c)  2000 2010 , Oracle  and / or  its affiliates. All rights reserved.
This software comes  with  ABSOLUTELY NO WARRANTY. This is free software,
and  you are welcome to modify  and  redistribute it under the GPL v2 license
Type  'help;'  or  '\h'  for  help. Type  '\c'  to clear the current input statement.
 
mysql> use mysql;
Database changed
mysql> flush privileges;
Query OK,  0  rows affected ( 0.00  sec)
mysql>









本文转自 客居天涯 51CTO博客,原文链接:http://blog.51cto.com/tiany/1557738,如需转载请自行联系原作者
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
2月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
525 5
|
3月前
|
关系型数据库 MySQL 数据管理
Mysql基础学习day03-作业
本内容包含数据库建表语句及多表查询示例,涵盖内连接、外连接、子查询及聚合统计,适用于员工与部门数据管理场景。
90 1
|
3月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day01
本课程为MySQL基础学习第一天内容,涵盖MySQL概述、安装、SQL简介及其分类(DDL、DML、DQL、DCL)、数据库操作(查询、创建、使用、删除)及表操作(创建、约束、数据类型)。适合初学者入门学习数据库基本概念和操作方法。
201 6
|
3月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day02-作业
本教程介绍了数据库表的创建与管理操作,包括创建员工表、插入测试数据、删除记录、更新数据以及多种查询操作,涵盖了SQL语句的基本使用方法,适合初学者学习数据库操作基础。
108 0
|
3月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day03
本课程为MySQL基础学习第三天内容,主要讲解多表关系与多表查询。内容涵盖物理外键与逻辑外键的区别、一对多、一对一及多对多关系的实现方式,以及内连接、外连接、子查询等多表查询方法,并通过具体案例演示SQL语句的编写与应用。
121 0
|
3月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day01-作业
本教程包含三个数据库表的创建练习:学生表(student)要求具备主键、自增长、非空、默认值及唯一约束;课程表(course)定义主键、非空唯一字段及数值精度限制;员工表(employee)包含自增主键、非空字段、默认值、唯一电话号及日期时间类型字段。每个表的结构设计均附有详细SQL代码示例。
97 0
|
3月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day02
本课程为MySQL基础学习第二天内容,涵盖数据定义语言(DDL)的表查询、修改与删除操作,以及数据操作语言(DML)的增删改查功能。通过具体SQL语句与实例演示,帮助学习者掌握MySQL表结构操作及数据管理技巧。
167 0
|
7月前
|
Ubuntu 关系型数据库 MySQL
mysql8.0安装初始化不需要设定root密码?
uubntu 的mysql安装完成后无法设定root密码
461 10
|
分布式计算 关系型数据库 MySQL
大数据-88 Spark 集群 案例学习 Spark Scala 案例 SuperWordCount 计算结果数据写入MySQL
大数据-88 Spark 集群 案例学习 Spark Scala 案例 SuperWordCount 计算结果数据写入MySQL
161 3
|
SQL 存储 关系型数据库
【MySQL基础篇】全面学习总结SQL语法、DataGrip安装教程
本文详细介绍了MySQL中的SQL语法,包括数据定义(DDL)、数据操作(DML)、数据查询(DQL)和数据控制(DCL)四个主要部分。内容涵盖了创建、修改和删除数据库、表以及表字段的操作,以及通过图形化工具DataGrip进行数据库管理和查询。此外,还讲解了数据的增、删、改、查操作,以及查询语句的条件、聚合函数、分组、排序和分页等知识点。
1075 56
【MySQL基础篇】全面学习总结SQL语法、DataGrip安装教程