mariadb重置自动id

Recently, I changed my website MySQL root user password. Then I thought what will happen if I forget the MySQL root password?

最近,我更改了我的网站MySQL root用户密码。 然后我想如果忘记MySQL的root密码会怎样?

Is there an easy way to reset the MySQL or MariaDB root password?

是否有一种简单的方法来重置MySQL或MariaDB根密码?

I looked through some online tutorials, but none of them seem to be complete enough to differentiate between changing the password and resetting the password. They seemed lacking the details about the MySQL table where user passwords are stored and in which columns.

我浏览了一些在线教程,但是它们似乎都不完整,无法区分更改密码和重置密码。 他们似乎缺少有关MySQL表的详细信息,该表存储了用户密码以及存储在哪些列中。

In this tutorial, we will learn the following topics.

在本教程中,我们将学习以下主题。

  1. How to Change MySQL/MariaDB root Password如何更改MySQL / MariaDB根密码
  2. How to Reset MySQL/MariaDB root Password如何重置MySQL / MariaDB根密码

I will try to make it as complete as possible, and hopefully after reading this, you will get through this task easily without the need of any further help.

我将尝试使其尽可能完整,阅读本文后,希望您可以轻松完成此任务,而无需任何其他帮助。

更改和重置密码有什么区别? (What is the difference between changing and resetting the password?)

If you know the root password, you can connect to the database as root user and then change the password very easily. You can change the root password as well as any other user password.

如果您知道root密码,则可以以root用户身份连接到数据库,然后非常容易地更改密码。 您可以更改root密码以及任何其他用户密码。

If you have forgotten the root password, means you can’t connect to the MySQL server as root user. The root user has the highest privileges and you can’t change its password through other accounts. We have to perform some additional steps in this case to reset the MySQL root password.

如果您忘记了root密码,则意味着您无法以root用户身份连接到MySQL服务器。 root用户具有最高的特权,您不能通过其他帐户更改其密码。 在这种情况下,我们必须执行一些其他步骤来重置MySQL根密码。

MySQL和MariaDB的步骤是否相同? (Steps for MySQL and MariaDB are Same?)

MariaDB is built on top of MySQL. It’s very popular for web hosting requirements. In fact, JournalDev and all my websites are using MariaDB database. Any command that works for MySQL will work for MariaDB as well.

MariaDB建立在MySQL之上。 对于Web托管要求,它非常受欢迎。 实际上,JournalDev和我所有的网站都使用MariaDB数据库。 任何适用于MySQL的命令也适用于MariaDB。

The only adjustment in the commands you might have to make is to stop and start of MySQL server. I am using Ubuntu for this tutorial and I use systemctl to start/stop services. You can also use /etc/init.d/mysql to perform the same operations.

您可能必须对命令进行的唯一调整是停止和启动MySQL服务器。 我在本教程中使用Ubuntu,并且使用systemctl启动/停止服务。 您也可以使用/etc/init.d/mysql来执行相同的操作。

If you are on Windows OS, then please use mysqld or mysqladmin from the command prompt to start or stop the MySQL server. They are located in the MySQL installation bin folder.

如果您使用的是Windows操作系统,请从命令提示符处使用mysqldmysqladmin来启动或停止MySQL服务器。 它们位于MySQL安装bin文件夹中。

如何更改MySQL或MariaDB根密码 (How to Change MySQL or MariaDB root Password)

I am using MariaDB database, we can use –version option to find out its version.

我正在使用MariaDB数据库,我们可以使用–version选项来查找其版本。


# mariadb --version
mariadb  Ver 15.1 Distrib 10.1.44-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
#

1.以root用户身份连接到MySQL (1. Connect to MySQL as root user)


# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

2.更改mysql.user表中的password和authentication_string值 (2. Change the password and authentication_string value in mysql.user table)

MySQL user passwords are stored in mysql.user table password and authentication_string columns in the encrypted form. We can use the PASSWORD() function to convert a plain-text string to the encrypted value and set these columns.

MySQL用户密码以加密形式存储在mysql.user表中的password和authentication_string列中。 我们可以使用PASSWORD()函数将纯文本字符串转换为加密值并设置这些列。


MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [mysql]> select password, authentication_string from user where User = 'root' AND Host = 'localhost';
+-------------------------------------------+-------------------------------------------+
| password                                  | authentication_string                     |
+-------------------------------------------+-------------------------------------------+
| *E510A8BC6807F8BF4913D893620792C432FCBA5B | *E510A8BC6807F8BF4913D893620792C432FCBA5B |
+-------------------------------------------+-------------------------------------------+
1 row in set (0.00 sec)MariaDB [mysql]> UPDATE user SET authentication_string = PASSWORD('qwerty2021') WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0MariaDB [mysql]> UPDATE user SET password = PASSWORD('qwerty2021') WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0MariaDB [mysql]> select password, authentication_string from user where User = 'root' AND Host = 'localhost';
+-------------------------------------------+-------------------------------------------+
| password                                  | authentication_string                     |
+-------------------------------------------+-------------------------------------------+
| *6F168491676C70E51CB8D0F14D6B581D1322A77A | *6F168491676C70E51CB8D0F14D6B581D1322A77A |
+-------------------------------------------+-------------------------------------------+
1 row in set (0.00 sec)MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> exit
Bye
root@localhost:~#

Let’s understand what’s happening in the above queries.

让我们了解以上查询中发生了什么。

  • First of all, we are changing the database to ‘mysql’首先,我们将数据库更改为“ mysql”
  • Then, we are setting ‘authentication_string’ and ‘password’ column values for ‘root’@’localhost’ user with the new password.然后,我们使用新密码为'root'@'localhost'用户设置'authentication_string'和'password'列值。
  • Then we are reloading the grant tables using the FLUSH PRIVILEGES command.然后,我们使用FLUSH PRIVILEGES命令重新加载授权表。
  • Then quit the MySQL session. The root password has been changed successfully.然后退出MySQL会话。 根密码已成功更改。

NOTE: I tried to use ALTER USER command to change the root password, but it didn’t work.

注意 :我尝试使用ALTER USER命令来更改root密码,但是它不起作用。


MariaDB [mysql]> ALTER USER root@localhost IDENTIFIED BY 'qwerty2022';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USER root@localhost IDENTIFIED BY 'qwerty2022'' at line 1
MariaDB [mysql]>

3.使用新密码验证root用户登录 (3. Verify the root user login using new password)


# mysql -uroot -pqwerty2021
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

That’s it. We have successfully changed the MySQL/MariaDB user password.

而已。 我们已经成功更改了MySQL / MariaDB用户密码。

如何重置MySQL / MariaDB根密码 (How to Reset the MySQL/MariaDB root Password)

If you have forgotten the root password, then we need to perform one extra step so that we can login to the MySQL terminal without providing the password.

如果您忘记了root密码,那么我们需要执行一个额外的步骤,以便我们无需提供密码即可登录MySQL终端。

1.停止MySQL服务器 (1. Stop the MySQL Server)


# systemctl stop mysql

You can also run systemctl stop mariadb, the effect will be the same.

您也可以运行systemctl stop mariadb ,效果将相同。

2.在没有权限检查设置的情况下启动MySQL Server (2. Starting the MySQL Server without permission checking setting)

The idea is to start the MySQL server without loading the grant tables information, so that we can login as root user without providing password.

这个想法是在不加载授权表信息的情况下启动MySQL服务器,以便我们可以以root用户身份登录而无需提供密码。

It’s a security risk to run MySQL server like this, so it must be done briefly and shut down immediately after resetting the root password.

像这样运行MySQL服务器会带来安全隐患,因此必须简短地进行此操作,并在重置root密码后立即将其关闭。

We can start the MySQL server in safe mode and pass –skip-grant-tables option to skip loading grant tables that store the user privileges settings.

我们可以在安全模式下启动MySQL服务器,并传递–skip-grant-tables选项以跳过加载存储用户权限设置的授权表。


# sudo mysqld_safe --skip-grant-tables --skip-networking &
[1] 11734
root@localhost:~# 200427 20:05:40 mysqld_safe Logging to syslog.
200427 20:05:40 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
#

It is important to run the command ending with & so that it runs in the background. I am also passing –skip-networking option to skip networking that prevents other clients from connecting to the MySQL server.

重要的是,运行以&结尾的命令,以使其在后台运行。 我还传递了–skip-networking选项以跳过网络连接,该网络阻止其他客户端连接到MySQL服务器。

3.以root用户身份连接到MySQL服务器,而无需传递密码 (3. Connect to MySQL Server as root without passing password)


# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

Notice that we are not providing root password, but still we are able to connect to MySQL server.

注意,我们没有提供root密码,但是我们仍然能够连接到MySQL服务器。

4.重置mysql.user表中的root密码 (4. Reset the root password in mysql.user table)


MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [mysql]> UPDATE user SET authentication_string = PASSWORD('qwerty2022') WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0MariaDB [mysql]> UPDATE user SET password = PASSWORD('qwerty2022') WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> exit
Bye
#
Mysql Reset Root Password
Mysql重置根密码

5.停止并启动MySQL服务器 (5. Stop and Start the MySQL server)

First of all, we will kill the running MySQL server. The PID is present in the /var/run/mysqld/mysqld.pid file.

首先,我们将终止正在运行MySQL服务器。 PID位于/var/run/mysqld/mysqld.pid文件中。


# cat /var/run/mysqld/mysqld.pid
11891
# sudo kill 11891
#

Now, start the MySQL server in the normal mode.

现在,以正常模式启动MySQL服务器。


# systemctl start mysql

6.通过使用新密码以root用户身份登录进行验证 (6. Verify by logging as root user with new password)


# mysql -uroot -pqwerty2022
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

If you will try to login as root without password, it will throw “Access denied” error.

如果您尝试以没有密码的root用户身份登录,则会引发“拒绝访问”错误。


# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
#

结论 (Conclusion)

MySQL root user is just like any other user. However, changing or resetting its password is a bit tricky because it’s the super user and we can’t change root password from another user login.

MySQL根用户与其他任何用户一样。 但是,更改或重置其密码有点棘手,因为它是超级用户,我们无法从其他用户登录名更改root密码。

翻译自: https://www.journaldev.com/39274/change-reset-mysql-mariadb-root-password

mariadb重置自动id

mariadb重置自动id_如何更改/重置MySQL或MariaDB根密码相关推荐

  1. Mysql当前的根密码核查_在MySQL数据库中复位根用户的密码的方法

    如果你从未为MySQL设置根用户密码,服务器在以根用户身份进行连接时不需要密码.但是,建议你为每个账户设置密码. 如果你以前设置了根用户密码,但却忘记了该密码,可设置新的密码.下述步骤是针对Windo ...

  2. mysql 自动增量_MySQL重置自动增量值

    在本教程中,我们将向您展示如何重置MySQL中AUTO_INCREMENT列的自动增量值. MySQL提供了一个有用的功能,称为自动增量. 您可以将自动递增属性分配给表的列,以生成新行的唯一标识. 通 ...

  3. 吊打MySQL,MariaDB到底强在哪?

    " 近年来,不少程序员在吹捧 MariaDB,抛弃 MySQL.本文总结了一些  MariaDB 强过 MySQL 的地方,分享给大家! 图片来自 Pexels MySQL 的发展史 MyS ...

  4. MySQL—Mysql与MariaDB启停命令的区别

    MySQL MySQL启动 service mysqld start或者/bin/systemctl start mysqld.service MySQL状态 service mysqld statu ...

  5. 性能超过MySQL的MariaDB到底强在哪里?

    你知道的越多,不知道的就越多,业余的像一棵小草! 你来,我们一起精进!你不来,我和你的竞争对手一起精进! 编辑:业余草 blog.csdn.net/zhmh326/article/details/10 ...

  6. mysql重置增量_摆脱困境:在每种测试方法之前重置自动增量列

    mysql重置增量 当我们为将信息保存到数据库的功能编写集成测试时,我们必须验证是否将正确的信息保存到数据库. 如果我们的应用程序使用Spring Framework,则可以为此目的使用Spring ...

  7. 摆脱困境:在每种测试方法之前重置自动增量列

    当我们为将信息保存到数据库的功能编写集成测试时,我们必须验证是否将正确的信息保存到数据库. 如果我们的应用程序使用Spring Framework,则可以为此目的使用Spring Test DbUni ...

  8. access自动编号怎么解除_如何在 Access 中重置“自动编号”字段值

    如何在 Access 中重置"自动编号"字段值 中删除某个表中的一些行或所有行时,"自动编号"字段不会自动重置.要重置"自动编号"字段值并 ...

  9. layui 搜索 重置 自动刷新

    搜索 重置 自动刷新

最新文章

  1. Revit: Twinmotion工作流程学习
  2. 新一代人工智能专利分析
  3. 使用VS2012内建的C++测试架构进行单元测试
  4. 远控免杀专题8---BackDoor-Facktory免杀
  5. EchoServer
  6. 论文浅尝 - COLING2020 | 一种用于跨语言实体对齐的上下文对齐强化跨图谱注意力网络...
  7. mysql 包含的那些文件
  8. java基础案例教程试题,Java基础案例教程-中国大学mooc-试题题目及答案
  9. 支撑Java NIO 与 NodeJS的底层技术
  10. mysql调试问题_mysql 数据库调试分析
  11. height、clientHeight、scrollHeight、offsetHeight区别
  12. 1.vue前端项目实战-登录功能
  13. SMI-FGSM:空间动量提高对抗迁移性
  14. wgs84坐标系拾取工具_Wgs84坐标系转换为gcj02坐标系及bd09坐标系的验证
  15. 电脑本地进行演讲者模式预览快捷键
  16. 分享一种快速制作二维码标签及防伪溯源二维码的方法
  17. 虚拟键盘 html,Jquery虚拟键盘(VirtualKeyboard)
  18. 计算机CPU的时钟频率主要,cpu时钟频率计算公式_CPU频率计算方法详解
  19. MATLAB绘制图中图
  20. 王树尧老师运筹学课程笔记 02 高等数学基础

热门文章

  1. Javascript项目
  2. [转载] PYTHON 网络编程
  3. loadrunner提高篇 - 关联技术的经典使用
  4. Python学习路程day9
  5. c#获取带有汉字的字符串长度
  6. PostgreSQL的 initdb 源代码分析之十六
  7. hashtable的C++实现
  8. Visual C++ 2011-5-18
  9. 超炫JS拖拽翻页效果(左右拖拽html源码)
  10. 文件的I/O c++