前言
mysql 更新完密码,总是拒绝连接、登录失败?MySQL8.0 不能通过直接修改 mysql.user 表来更改密码。正确更改密码的方式备注: 清空root密码
MySQL8.0 不能通过直接修改 mysql.user 表来更改密码。
因为authentication_string字段下只能是MySQL加密后的43位字符串密码,其他的导致错误。错误不报出,但是无法再登录mysql,总是会提示 无法认证。
参考:MySQL8.0
mysql> USE mysql; Database changed mysql> UPDATE user SET authentication_string="123456" WHERE user="root"; Query OK, 1 row affected (0.39 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> FLUSH privileges; # 刷新保存 Query OK, 0 rows affected (0.13 sec)
mysql 5.7.9 之后取消了password 函数,authentication_string=password("123456") 会报错
C:\WINDOWS\system32>mysql -u root -p
Enter password: ******
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
1234567891011121314
如果 你已经这样更改密码,并且导致了无法进入mysql。本人表示同情之时,还为了你提供了详细的解决方案。请查看本文备注:清空root 密码
正确更改密码的方式
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "your_password"; mysql> USE mysql; Database changed mysql> ALTER USER 'root'@'localhost' IDENTIFIEED WITH mysql_native_password BY "markjun"; 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 'IDENTIFIEED WITH mysql_native_password BY "markjun"' at line 1 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "markjun"; Query OK, 0 rows affected (0.18 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "123456"; Query OK, 0 rows affected (0.08 sec) mysql> SELECT user, authentication_string FROM user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +------------------+------------------------------------------------------------------------+ 4 rows in set (0.00 sec) mysql> FLUSH privileges; Query OK, 0 rows affected (0.38 sec) mysql> quit; Bye F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p Enter password: ******* ... mysql>
备注: 清空root密码
停止 MySQL 任务 net stop MySQL
mysqld 命令 mysqld --console --skip-grant-tables --shared-memory
无密码进入mysql mysql -u root
清空root 密码 UPDATE user SET authentication_string="" WHERE user=“root”;
另一个终端无密码进入
F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p Enter password: ******* ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 ... Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> USE mysql; Database changed mysql> SELECT user, authentication_string FROM user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | root | 123456 | +------------------+------------------------------------------------------------------------+ 4 rows in set (0.34 sec) mysql> UPDATE user SET authentication_string="" WHERE user="root"; Query OK, 1 row affected (0.20 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT user, authentication_string FROM user; +------------------+------------------------------------------------------------------------+ | user | authentication_string | +------------------+------------------------------------------------------------------------+ | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | root | | +------------------+------------------------------------------------------------------------+ 4 rows in set (0.00 sec) mysql> FLUSH privileges; Query OK, 0 rows affected (0.10 sec) mysql> quit; Bye
你可以通过停止 mysqld 进程、在运行 mysqld 的 cmd 终端中使用 Ctrl+C 结束任务,或者直接关闭终端来结束 mysqld 任务。
需要先停止运行上述 mysqld 任务,否则报错
F:\MySQL\mysql-8.0.13-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务无法启动。服务没有报告任何错误。
请键入 NET HELPMSG 3534 以获得更多的帮助。
先停止上述 mysqld 任务
F:\MySQL\mysql-8.0.13-winx64\bin>net start mysql
MySQL 服务正在启动 ...
MySQL 服务已经启动成功。
现在 mysql root 已经没有了密码
F:\MySQL\mysql-8.0.13-winx64\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g....
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
The above is the detailed content of How to change the password correctly in MySQL8.0. For more information, please follow other related articles on the PHP Chinese website!

Installing MySQL on Linux can be done through the package manager. The specific steps are as follows: 1. On Ubuntu, use apt to update the package list and install the MySQL server; 2. On CentOS, use yum to install the MySQL community version and start the service. After installation, basic configuration needs to be performed, such as setting the root password and creating database and users.

MySQL views are virtual tables generated based on SQL queries. 1. Create a view: Use the CREATEVIEW statement combined with SELECT query. 2. Usage scenarios: simplify complex queries, data abstraction and ensure data consistency. 3. Optimization strategy: simplify underlying queries, use indexes, and consider materialized views.

When creating a database in MySQL, character sets and collation rules should be specified to ensure data accuracy and improve query performance. 1) Use the CREATEDATABASEmy_databaseCHARACTERSETutf8mb4COLLATIONutf8mb4_unicode_ci command to create a database, select the utf8mb4 character set and utf8mb4_unicode_ci collation. 2) utf8mb4 supports more Unicode characters, while utf8mb4_unicode_ci provides case-insensitive comparisons. 3) Ensure that the application layer and database layer use the same character set and collation rules to avoid potential problems.

In MySQL, sorting uses the ORDERBY clause, and ranking uses the RANK(), DENSE_RANK(), and ROW_NUMBER() functions. 1. Sort: Use ORDERBY clause, such as SELECT*FROMemployeesORDERBYsalaryDESC; 2. Ranking: Use window functions, such as SELECTemployee_name, salary, RANK()OVER(ORDERBYsalaryDESC)ASrankFROMemployees; these operations are based on SQL query optimizer and execution engine, and are often used to sort quickly or merge sort, and ranking depends on window function calculation.

To create and call stored procedures in MySQL, follow the following steps: 1. Create stored procedures: Use the CREATEPROCEDURE statement to define stored procedures, including names, parameters, and SQL statements. 2. Compile stored procedures: MySQL compiles stored procedures into executable code and stores them. 3. Call stored procedure: use CALL statement and pass parameters. 4. Execute stored procedures: MySQL executes the SQL statements in it, processes parameters and returns the result.

The MySQL service can be set to automatically start on Windows, Linux, and macOS. 1) On Windows, use the command "scconfigmysqlstart=auto" to configure. 2) On Linux, enable it using "sudosystemctlenablemysql". 3) On macOS, create and load the launchd configuration file to achieve automatic startup.

The methods to view the MySQL table structure include: 1. Use the DESCRIBE command to view column information; 2. Use the SHOWCREATETABLE command to view table creation statements; 3. Use information_schema to query more detailed information. These methods help to quickly understand table structure and improve work efficiency.

Installing MySQL on macOS can be achieved through the following steps: 1. Install Homebrew, using the command /bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)". 2. Update Homebrew and use brewupdate. 3. Install MySQL and use brewinstallmysql. 4. Start MySQL service and use brewservicesstartmysql. After installation, you can use mysql-u


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment
