Mysql 8 thay đổi mật khẩu root

Tất cả chúng ta đã ở đó. Bạn đã quên mật khẩu root MySQL hoặc nó đã thay đổi một cách bí ẩn 🤔. Rất may, có một cách giải quyết vấn đề này bằng cách sử dụng tùy chọn

mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper
7

Trước khi bắt đầu, nếu bạn gặp sự cố khi đăng nhập vào phpMyAdmin và gặp lỗi Truy cập bị từ chối đối với người dùng ‘root’@’localhost’, nhưng bạn chắc chắn mật khẩu root của mình là chính xác, vui lòng tham khảo bài viết này trước. Không thể đăng nhập vào phpMyAdmin. mysqli_real_connect(). (HY000/1698). Quyền truy cập bị từ chối đối với người dùng ‘root’@’localhost’

1. Xác nhận phiên bản MySQL

Trước tiên, bạn phải xác nhận phiên bản MySQL trên Ubuntu mà bạn đang chạy vì các lệnh sẽ khác nhau

mysql -V

Nếu trên MySQL phiên bản 8, bạn sẽ thấy một cái gì đó giống như

mysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

Nếu bạn đang dùng MySQL phiên bản 5, bạn sẽ thấy nội dung tương tự như

mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper

2. Khởi động lại MySQL với bỏ qua-cấp-bảng

Để bỏ qua các bảng cấp và đặt lại mật khẩu gốc, trước tiên chúng ta phải dừng dịch vụ MySQL. Nhập mật khẩu Linux của bạn nếu được nhắc

sudo /etc/init.d/mysql stop

Đảm bảo thư mục 

mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper
8 tồn tại và đặt đúng chủ sở hữu

sudo mkdir /var/run/mysqld

sudo chown mysql /var/run/mysqld

Bây giờ hãy bắt đầu MySQL với tùy chọn 

mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper
7.
sudo /etc/init.d/mysql stop
0 là bắt buộc ở đây

sudo mysqld_safe --skip-grant-tables&

Bạn sẽ thấy một cái gì đó tương tự

[1] 1283
user@server:~$ 2019-02-12T11:15:59.872516Z mysqld_safe Logging to syslog.
2019-02-12T11:15:59.879527Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2019-02-12T11:15:59.922502Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

Bây giờ hãy nhấn

sudo /etc/init.d/mysql stop
1 để quay lại lời nhắc Linux BASH

3. Thay đổi mật khẩu gốc MySQL

Giờ đây, bạn có thể đăng nhập vào tài khoản root MySQL mà không cần mật khẩu

sudo mysql --user=root mysql

Sau khi đăng nhập, bạn sẽ thấy lời nhắc 

sudo /etc/init.d/mysql stop
2

MySQL 8 – Đặt lại mật khẩu gốc

Đối với MySQL 8 trên Ubuntu, hãy chạy các lệnh sau

UPDATE mysql.user SET authentication_string=null WHERE User='root';

mysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
0

Thay thế 

sudo /etc/init.d/mysql stop
3 bằng của riêng bạn. (Tạo mật khẩu mạnh tại đây)

mysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
1

Xóa đặc quyền một lần nữa

mysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
0

Thoát MySQL

mysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
3

Bây giờ bỏ qua bên dưới

mysql 5. 7 – Đặt lại mật khẩu gốc

Đối với MySQL 5. 7 trên Ubuntu, hãy chạy lệnh này để thay đổi mật khẩu gốc. Thay thế 

sudo /etc/init.d/mysql stop
3 bằng của riêng bạn. (Tạo mật khẩu mạnh tại đây)

Bạn đã quên mật khẩu người dùng cơ sở dữ liệu MySQL của mình

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1? . Hướng dẫn từng bước này giải thích cách đặt lại mật khẩu gốc trong MySQL 8 trên Ubuntu 20. 04 hệ điều hành

Ghi chú. Như bạn có thể đã biết, người dùng root MySQL sử dụng plugin

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
2 để xác thực với máy chủ MySQL trong các hệ thống Ubuntu chạy MySQL 5. 7 và các phiên bản mới hơn. Vì vậy, bạn có thể đăng nhập vào máy chủ MySQL với tư cách là người dùng
● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1 bằng lệnh
● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
4 miễn là bạn biết mật khẩu
● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
5 của người dùng hệ thống. Trong trường hợp đó, không cần thiết phải thay đổi mật khẩu MySQL
● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1. Nếu bạn đã thay đổi phương thức xác thực cho người dùng root MySQL thành
● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
7 hoặc
● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
8, hãy làm theo các bước bên dưới để đặt lại mật khẩu
● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1 của cơ sở dữ liệu MySQL

Đặt lại mật khẩu gốc trong MySQL 8 trên Ubuntu Linux

1. Đầu tiên, dừng dịch vụ MySQL bằng lệnh

$ sudo systemctl stop mysql

Điều này sẽ dừng dịch vụ MySQL nếu nó đang chạy. Bạn có thể xác minh trạng thái của dịch vụ MySQL bằng lệnh

$ sudo systemctl status mysql

đầu ra mẫu

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.

Mysql 8 thay đổi mật khẩu root
Dừng dịch vụ MySQL

2. Tiếp theo, khởi động máy chủ MySQL mà không cần kiểm tra quyền. Để làm như vậy, hãy chạy

$ sudo systemctl edit mysql

Thao tác này sẽ mở tệp cấu hình

$ sudo systemctl edit mysql
0
$ sudo systemctl edit mysql
1 trình soạn thảo văn bản mặc định của bạn. Trong trường hợp của tôi, đó là biên tập viên
$ sudo systemctl edit mysql
2

Thêm các dòng sau vào đó

[Service]
ExecStart=
ExecStart=/usr/sbin/mysqld --skip-grant-tables --skip-networking

Mysql 8 thay đổi mật khẩu root
Chỉnh sửa tệp cấu hình mysql systemd

Sau khi thêm các dòng trên, nhấn

$ sudo systemctl edit mysql
3 và
$ sudo systemctl edit mysql
4 để lưu tệp rồi nhấn
$ sudo systemctl edit mysql
5 để đóng tệp

Tại đây, tùy chọn

$ sudo systemctl edit mysql
6 cho phép bạn kết nối với máy chủ cơ sở dữ liệu MySQL mà không cần mật khẩu và có tất cả các đặc quyền. Nó cũng sẽ vô hiệu hóa các câu lệnh quản lý tài khoản như
$ sudo systemctl edit mysql
7 và
$ sudo systemctl edit mysql
8. Và tùy chọn
$ sudo systemctl edit mysql
9 được sử dụng để ngăn các máy khách khác kết nối với máy chủ cơ sở dữ liệu. Vì nó vô hiệu hóa tất cả các kết nối từ xa, không máy khách từ xa nào có thể truy cập máy chủ cơ sở dữ liệu cho đến khi bạn khởi động lại máy chủ cơ sở dữ liệu bình thường

3. Tải lại cấu hình

$ sudo systemctl edit mysql
1 bằng lệnh

$ sudo systemctl daemon-reload

4. Bắt đầu dịch vụ MySQL

$ sudo systemctl start mysql

Thao tác này sẽ khởi động máy chủ MySQL với các tùy chọn

[Service]
ExecStart=
ExecStart=/usr/sbin/mysqld --skip-grant-tables --skip-networking
1 và
$ sudo systemctl edit mysql
9. Bạn có thể xác minh bằng cách kiểm tra trạng thái dịch vụ MySQL

$ sudo systemctl status mysql
 ● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Drop-In: /etc/systemd/system/mysql.service.d
              └─override.conf
      Active: active (running) since Mon 2021-05-31 11:39:18 UTC; 1min 23s ago
     Process: 1882 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
    Main PID: 1905 (mysqld)
      Status: "Server is operational"
       Tasks: 36 (limit: 2280)
      Memory: 331.0M
      CGroup: /system.slice/mysql.service
              └─1905 /usr/sbin/mysqld --skip-grant-tables --skip-networking
 May 31 11:39:16 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 11:39:18 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.

5. Bây giờ, hãy kết nối với máy chủ MySQL với tư cách là người dùng

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1 mà không cần mật khẩu

$ sudo mysql -u root

Bạn sẽ được hạ cánh bên trong MySQL shell prompt ngay lập tức

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.25-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

6. Chúng tôi đã đăng nhập vào máy chủ cơ sở dữ liệu mà không tải các bảng cấp (vì chúng tôi đã sử dụng tùy chọn

$ sudo systemctl edit mysql
6). Vì vậy, chúng tôi không thể sử dụng lệnh
$ sudo systemctl edit mysql
7 mà anh ấy cần để đặt lại mật khẩu. Để tải các bảng cấp, hãy chạy lệnh sau từ MySQL shell prompt

$ sudo systemctl status mysql
0

7. Tiếp theo, chạy bất kỳ lệnh nào sau đây để đặt lại mật khẩu MySQL

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1

Nếu bạn đang sử dụng plugin

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
7, hãy chạy

$ sudo systemctl status mysql
1

Mysql 8 thay đổi mật khẩu root
Đặt lại mật khẩu root trong MySQL 8 trên Ubuntu Linux

Nếu bạn sử dụng plugin

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
8, hãy chạy plugin này để thay thế

$ sudo systemctl status mysql
2

Thay thế

[Service]
ExecStart=
ExecStart=/usr/sbin/mysqld --skip-grant-tables --skip-networking
9 bằng của riêng bạn

Sau khi thay đổi mật khẩu MySQL

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1, hãy thoát khỏi dấu nhắc vỏ MySQL

$ sudo systemctl status mysql
3

8. Hoàn nguyên cấu hình

$ sudo systemctl edit mysql
1 đã sửa đổi về cài đặt bình thường bằng lệnh

$ sudo systemctl status mysql
4

Thao tác này sẽ xóa tất cả các tệp đã sửa đổi

$ sudo systemctl status mysql
5

9. Tải lại cấu hình

$ sudo systemctl edit mysql
1 để các thay đổi có hiệu lực

$ sudo systemctl daemon-reload

10. Cuối cùng, khởi động lại máy chủ MySQL bình thường

$ sudo systemctl status mysql
7

11. Bây giờ bạn sẽ có thể kết nối với cơ sở dữ liệu MySQL với tư cách là người dùng

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1 bằng lệnh sử dụng
$ sudo systemctl daemon-reload
4

$ sudo systemctl status mysql
8

Nhập mật khẩu

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1 để truy cập MySQL shell prompt

$ sudo systemctl status mysql
9

Ngoài ra còn có một cách khác để thay đổi mật khẩu MySQL

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
1 trong Linux. Nó hơi khác so với phương pháp này. Nếu bạn muốn biết, hãy xem liên kết sau

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: inactive (dead) since Mon 2021-05-31 11:01:15 UTC; 1min 15s ago
     Process: 1446 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
    Main PID: 1446 (code=exited, status=0/SUCCESS)
      Status: "Server shutdown complete"
 May 31 07:57:50 ubuntu2004.localdomain systemd[1]: Starting MySQL Community Server…
 May 31 07:57:51 ubuntu2004.localdomain systemd[1]: Started MySQL Community Server.
 May 31 11:01:14 ubuntu2004.localdomain systemd[1]: Stopping MySQL Community Server…
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: mysql.service: Succeeded.
 May 31 11:01:15 ubuntu2004.localdomain systemd[1]: Stopped MySQL Community Server.
0

Phần kết luận

Như bạn có thể thấy, việc đặt lại mật khẩu root của MySQL rất dễ dàng. Nếu bạn làm theo các bước trên một cách cẩn thận, bạn có thể khôi phục mật khẩu gốc cơ sở dữ liệu MySQL của mình sau vài phút. Đừng đánh mất nó một lần nữa. Ghi nhớ hoặc lưu mật khẩu của bạn ở một nơi an toàn

Làm cách nào để thay đổi mật khẩu người dùng root MySQL?

Để thay đổi mật khẩu gốc, hãy nhập nội dung sau tại dấu nhắc lệnh của MySQL/MariaDB. THAY ĐỔI NGƯỜI DÙNG 'root'@'localhost' ĐƯỢC XÁC ĐỊNH BỞI 'MyN3wP4ssw0rd'; . Store the new password in a secure location.

Mật khẩu gốc mặc định cho MySQL 8 là gì?

Người dùng mặc định cho MySQL là root và theo mặc định, nó có không có mật khẩu .

Làm cách nào để đặt lại mật khẩu MySQL trong CentOS 8?

Đặt lại mật khẩu gốc đã quên .
/# chroot /sysroot. Bây giờ bạn sẽ có thể thay đổi mật khẩu gốc. .
/# mật khẩu gốc. Sau đó, bạn sẽ được yêu cầu nhập mật khẩu mới và sau đó xác nhận mật khẩu đó. .
/# chạm /. nhãn tự động. Sau khi dán nhãn lại, hãy sử dụng lệnh sau để lưu và áp dụng các thay đổi
/# lối ra. .
/# khởi động lại

Làm cách nào để thay đổi mật khẩu root MySQL trong Ubuntu?

Cách thay đổi mật khẩu gốc MySQL trong Ubuntu .
Bước 1. Kiểm tra phiên bản MySQL trên Ubuntu 20. 04
Bước 2. Dừng máy chủ MySQL
Bước 3. Bỏ qua bảng cấp & kết nối mạng
Bước 4. Bắt đầu dịch vụ MySQL
Bước 5. Đăng nhập vào vỏ MySQL
Bước 6. Thay đổi mật khẩu gốc