Hướng dẫn how do i change the mysql root password in centos 7? - làm cách nào để thay đổi mật khẩu root mysql trong centos 7?

Bạn đang sử dụng phiên bản MySQL nào? Tôi đang sử dụng 5.7.10 và có cùng một vấn đề với việc đăng nhập như root

Có 2 vấn đề - tại sao tôi không thể đăng nhập làm root để bắt đầu và tại sao tôi không thể sử dụng 'mysqld_safe` để bắt đầu mysql để đặt lại mật khẩu gốc.

Tôi không có câu trả lời để thiết lập mật khẩu gốc trong quá trình cài đặt, nhưng đây là những gì bạn làm để đặt lại mật khẩu gốc

Chỉnh sửa mật khẩu gốc ban đầu khi cài đặt có thể được tìm thấy bằng cách chạy the initial root password on install can be found by running

grep 'temporary password' /var/log/mysqld.log

http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html


  1. systemd hiện được sử dụng để chăm sóc MySQL thay vì mysqld_safe (đó là lý do tại sao bạn gặp lỗi

    1. Stop mysql:
    sudo systemctl stop mysqld
    
    2. Set the mySQL environment option 
    sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
    
    3. Start mysql usig the options you just set
    sudo systemctl start mysqld
    
    4. Login as root
    mysql -u root
    
    5. Update the root user password with these mysql commands
    mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
        -> WHERE User = 'root' AND Host = 'localhost';
    mysql> FLUSH PRIVILEGES;
    mysql> quit
    
    *** Edit ***
    As mentioned my shokulei in the comments, for 5.7.6 and later, you should use 
       mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    Or you'll get a warning
    
    6. Stop mysql
    sudo systemctl stop mysqld
    
    7. Unset the mySQL envitroment option so it starts normally next time
    sudo systemctl unset-environment MYSQLD_OPTS
    
    8. Start mysql normally:
    sudo systemctl start mysqld
    
    Try to login using your new password:
    7. mysql -u root -p
    
    0 - nó chưa được cài đặt)

  2. Cấu trúc bảng

    1. Stop mysql:
    sudo systemctl stop mysqld
    
    2. Set the mySQL environment option 
    sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
    
    3. Start mysql usig the options you just set
    sudo systemctl start mysqld
    
    4. Login as root
    mysql -u root
    
    5. Update the root user password with these mysql commands
    mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
        -> WHERE User = 'root' AND Host = 'localhost';
    mysql> FLUSH PRIVILEGES;
    mysql> quit
    
    *** Edit ***
    As mentioned my shokulei in the comments, for 5.7.6 and later, you should use 
       mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    Or you'll get a warning
    
    6. Stop mysql
    sudo systemctl stop mysqld
    
    7. Unset the mySQL envitroment option so it starts normally next time
    sudo systemctl unset-environment MYSQLD_OPTS
    
    8. Start mysql normally:
    sudo systemctl start mysqld
    
    Try to login using your new password:
    7. mysql -u root -p
    
    1 đã thay đổi.

Vì vậy, để đặt lại mật khẩu gốc, bạn vẫn bắt đầu MySQL với các tùy chọn

1. Stop mysql:
sudo systemctl stop mysqld

2. Set the mySQL environment option 
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. Start mysql usig the options you just set
sudo systemctl start mysqld

4. Login as root
mysql -u root

5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
    -> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit

*** Edit ***
As mentioned my shokulei in the comments, for 5.7.6 and later, you should use 
   mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Or you'll get a warning

6. Stop mysql
sudo systemctl stop mysqld

7. Unset the mySQL envitroment option so it starts normally next time
sudo systemctl unset-environment MYSQLD_OPTS

8. Start mysql normally:
sudo systemctl start mysqld

Try to login using your new password:
7. mysql -u root -p
2 và cập nhật bảng
1. Stop mysql:
sudo systemctl stop mysqld

2. Set the mySQL environment option 
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. Start mysql usig the options you just set
sudo systemctl start mysqld

4. Login as root
mysql -u root

5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
    -> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit

*** Edit ***
As mentioned my shokulei in the comments, for 5.7.6 and later, you should use 
   mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Or you'll get a warning

6. Stop mysql
sudo systemctl stop mysqld

7. Unset the mySQL envitroment option so it starts normally next time
sudo systemctl unset-environment MYSQLD_OPTS

8. Start mysql normally:
sudo systemctl start mysqld

Try to login using your new password:
7. mysql -u root -p
1, nhưng cách bạn làm nó đã thay đổi.

1. Stop mysql:
sudo systemctl stop mysqld

2. Set the mySQL environment option 
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. Start mysql usig the options you just set
sudo systemctl start mysqld

4. Login as root
mysql -u root

5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
    -> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit

*** Edit ***
As mentioned my shokulei in the comments, for 5.7.6 and later, you should use 
   mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Or you'll get a warning

6. Stop mysql
sudo systemctl stop mysqld

7. Unset the mySQL envitroment option so it starts normally next time
sudo systemctl unset-environment MYSQLD_OPTS

8. Start mysql normally:
sudo systemctl start mysqld

Try to login using your new password:
7. mysql -u root -p

Tài liệu tham khảo

Như đã nói tại http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html,

Ghi chú

Kể từ MySQL 5.7.6, để cài đặt MySQL bằng cách sử dụng phân phối RPM, khởi động và tắt máy chủ được quản lý bởi SystemD trên một số nền tảng Linux. Trên các nền tảng này, mysqld_safe không còn được cài đặt vì nó không cần thiết. Để biết thêm thông tin, xem Phần 2.5.10, Quản lý máy chủ MySQL với SystemD.

Điều này đưa bạn đến http://dev.mysql.com/doc/refman/5.7/en/server-man quản lý-using-systemd.html nơi nó đề cập đến

1. Stop mysql:
sudo systemctl stop mysqld

2. Set the mySQL environment option 
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. Start mysql usig the options you just set
sudo systemctl start mysqld

4. Login as root
mysql -u root

5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
    -> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit

*** Edit ***
As mentioned my shokulei in the comments, for 5.7.6 and later, you should use 
   mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Or you'll get a warning

6. Stop mysql
sudo systemctl stop mysqld

7. Unset the mySQL envitroment option so it starts normally next time
sudo systemctl unset-environment MYSQLD_OPTS

8. Start mysql normally:
sudo systemctl start mysqld

Try to login using your new password:
7. mysql -u root -p
4 về phía dưới của trang.

Các lệnh đặt lại mật khẩu nằm ở dưới cùng của http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

Khởi động máy chủ MySQL/Mariadb mà không cần tải các bảng tài trợ. ....MySQL, Linux


Đăng nhập vào vỏ MySQL. ....

Đặt mật khẩu gốc mới. ....

sudo systemctl stop mysqld

Dừng và khởi động máy chủ cơ sở dữ liệu bình thường. ....

sudo mysqld_safe --skip-grant-tables &

Xác minh mật khẩu ..

Làm cách nào để thay đổi mật khẩu gốc mysql?

mysql -uroot

Để thay đổi mật khẩu gốc, hãy nhập thông tin sau vào dấu nhắc lệnh mysql/mariadb: thay đổi người dùng 'root'@'localhost' được xác định bởi 'myn3wp4SSW0RD'; đặc quyền xả nước; Thoát; lưu trữ mật khẩu mới ở một vị trí an toàn.

use mysql;
update user set authentication_string=PASSWORD("mypassword") where User='root';
flush privileges;
quit

Mật khẩu mặc định cho MySQL trong Centos 7 là gì?

sudo systemctl stop mysqld
sudo systemctl start mysqld

Không có mật khẩu mặc định (mật khẩu trống) cho máy chủ cơ sở dữ liệu MySQL. Bạn cần gán mật khẩu gốc sau khi cài đặt MySQL thông qua lệnh YUM / RPM. Một số quản trị viên đặt mật khẩu gốc giống như mật khẩu gốc máy chủ.

mysql -uroot -p

Cập nhật lần cuối vào ngày 27 tháng 12 năm 2019 tại MySQL, Linux


Đặt lại mật khẩu gốc MySQL trong CentOS 7 là thẳng.

Dừng máy chủ MySQL

Hướng dẫn how do i change the mysql root password in centos 7? - làm cách nào để thay đổi mật khẩu root mysql trong centos 7?
Khởi động máy chủ MySQL/Mariadb mà không cần tải các bảng tài trợ. ....

Đăng nhập vào vỏ MySQL. ....

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

1.Stop mysql:Stop mysql:

Systemctl dừng MySQLDstop mysqld

2. Sắp đặt tùy chọn Môi trường MySQLSet the mySQL environment option

Systemctl Set-Môi trường MySQLD_OPTS = "-Bỏ qua Bảng Grant"set-environment MYSQLD_OPTS="--skip-grant-tables"

3. khởi động mysql usig các tùy chọn bạn vừa đặtStart mysql usig the options you just set

SystemCtl Bắt đầu MySQLDstart mysqld

4.Login asrootLogin asroot

mysql-uroot-uroot

5. Đơn trước mật khẩu người dùng gốc với các lệnh mysql nàyUpdate the root user password with these mysql commands

mysql> Cập nhật mysql.user đặt xác thực_string = mật khẩu ('mynewpassword'))>UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPassword')

& nbsp; & nbsp; & nbsp; & nbsp;-> trong đó user = 'root'andhost =' localhost ';->WHERE User= 'root'ANDHost='localhost';

mysql> đặc quyền tuôn ra;>FLUSH PRIVILEGES;

mysql>quit>quit

6.Thop mysqlStop mysql

Systemctl dừng MySQLDstop mysqld

7. Khun Unset the mySQL envitroment option so it starts normally next time

SystemCtl Und-đặt môi trường mysqld_optsunset-environment MYSQLD_OPTS

8. khởi động MySQL bình thường:Start mysql normally:

SystemCtl Bắt đầu MySQLDstart mysqld

4.Login asroot tologin using your newpassword:

7.mysql-uroot-pmysql-uroot-p

5. Đơn trước mật khẩu người dùng gốc với các lệnh mysql này
Note

mysql> Cập nhật mysql.user đặt xác thực_string = mật khẩu ('mynewpassword'))

& nbsp; & nbsp; & nbsp; & nbsp;-> trong đó user = 'root'andhost =' localhost ';

Nhiều tùy chọn cho mysqld_safe giống như các tùy chọn cho mysqld. Xem Phần 6.1.4, Tùy chọn lệnh máy chủ của Cameron.

Các tùy chọn chưa biết đến MySQLD_SAFE được truyền cho MySQLD nếu chúng được chỉ định trên dòng lệnh, nhưng bị bỏ qua nếu chúng được chỉ định trong nhóm [mysqld_safe] của tệp tùy chọn.

Làm thế nào đặt mật khẩu gốc mysql trong centos?

Thực hiện theo các bước này để đặt lại mật khẩu gốc MySQL/MariaDB của bạn:..
Dừng dịch vụ MySQL/MariaDB.....
Khởi động máy chủ MySQL/Mariadb mà không cần tải các bảng tài trợ.....
Đăng nhập vào vỏ MySQL.....
Đặt mật khẩu gốc mới.....
Dừng và khởi động máy chủ cơ sở dữ liệu bình thường.....
Xác minh mật khẩu ..

Làm cách nào để thay đổi mật khẩu gốc mysql?

Để thay đổi mật khẩu gốc, hãy nhập thông tin sau vào dấu nhắc lệnh mysql/mariadb: thay đổi người dùng 'root'@'localhost' được xác định bởi 'myn3wp4SSW0RD';đặc quyền xả nước;Thoát; lưu trữ mật khẩu mới ở một vị trí an toàn.ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.

Mật khẩu mặc định cho MySQL trong Centos 7 là gì?

Không có mật khẩu mặc định (mật khẩu trống) cho máy chủ cơ sở dữ liệu MySQL.Bạn cần gán mật khẩu gốc sau khi cài đặt MySQL thông qua lệnh YUM / RPM.Một số quản trị viên đặt mật khẩu gốc giống như mật khẩu gốc máy chủ. for MySQL database server. You need to assign root password after installing MySQL via yum / rpm command. Some admin set the root password same as the server root password.