Solve the problem of changing the password when logging in for the first time after installing MySQL 8.0

Solve the problem of changing the password when logging in for the first time after installing MySQL 8.0

Here is an introduction to changing the password for the first login in MySQL 8.0.16

The password needs to be changed for the first login after the MySQL database is initialized

The following error will occur when you log in for the first time

ql> alter user root identified by 'password';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

You need to use the following command to change the password

mysql> alter user user() identified by 'password';
Query OK, 0 rows affected (1.43 sec)

ps: Let's take a look at the problems that occur when installing MySQL 8.0 + logging in for the first time + changing the password

Install

Because I had installed it before but on the C drive, this time I wanted to move it to the D drive, so I deleted the previously installed parts and only left the MySQL Installer file for installation. There is one tricky part, which is that the default installation directory is on the C drive. If you want to change the directory, then in the Choosing a Setup Type step, be sure to select Custom installation.

Then proceed here and select the project you want to install, for example, I will just choose one here

At this time, you will not see any option to change the installation directory. You need to select the one you want to install, and then there will be an extra link in the lower right corner. Click it to change the installation directory.

Note that if there are multiple things you want to install, you need to click on each of them and change their installation path one by one.

But there is still a problem. When changing the directory, this prompt may appear

I don't understand the reason, but the solution is to keep its original path name and only change or add in front of the path, like this

The following configuration mainly focuses on the setting of the port number. The default is 3306, but if there is a conflict, it means that the port is already occupied. In this case, you can change it to any value between 3306 and 3309.

After installation, remember to set the variables in the system environment variable Path for the convenience of cmd.

First login

There are many problems encountered, such as opening cmd, the first step is to execute

net start MySQL

Report an error...

The reason is that cmd is not run as an administrator

After changing to administrator identity, another problem occurred

I don't know why this problem occurred during the first run. I found a solution online and needed to initialize it.

mysqld --initialize

After the service is started, run

mysql -u root -p

Then you will be asked to enter your password. Here is another problem.

This prompt means that the password is wrong

I am also a little confused about this place. You were asked to set a password when installing MySQL earlier, but that password seems to be unused. What you should enter here is the random initial password it automatically generates, and this initial random password is placed in an .err file in the MySQL installation directory. It's not that hard to find. There seems to be only one .err file in the entire folder. Just search in the folder.

The file content is not long. Find this paragraph of text and the line below is the initial password.

After entering the password, it will show success.

Change Password

Changing passwords after MySQL 8.0 is different from before. Many of the previous methods will report errors if used now. I have tested the following code and it is feasible

ALTER USER "root"@"localhost" IDENTIFIED BY "your new password";

Summarize

The above is what I introduced to you to solve the problem of changing the password when logging in for the first time after installing MySQL 8.0. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed explanation of the idea of ​​installing mysql8.0.11 and changing the root password and connecting navicat for mysql
  • How to correctly modify the ROOT password in MySql8.0 and above versions
  • Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0
  • MySQL 8.0.19 winx64 installation tutorial and change the initial password under Windows 10
  • MySQL 8.0.12 installation configuration method and password change
  • MySQL 8.0.15 installation and configuration graphic tutorial and password change under Linux
  • How to modify the root user password in mysql 8.0.16 winx64 and Linux
  • Problems with changing password and connecting to Navicat when installing and using MySQL 8.0.16 under Windows 7
  • mysql8.0 forgotten password modification and net command service name invalid problem
  • The correct way to change the password in MySQL 8.0

<<:  Docker's flexible implementation of building a PHP environment

>>:  Detailed explanation of how to use the vue verification code component

Recommend

Research on the value of position attribute in CSS (summary)

The CSS position attribute specifies the element&...

Solve the problem of inconsistent front and back end ports of Vue

Vue front and back end ports are inconsistent In ...

Vue.js implements the nine-grid image display module

I used Vue.js to make a nine-grid image display m...

Linux implements the source code of the number guessing game

A simple Linux guessing game source code Game rul...

Summary of three ways to create new elements

First: via text/HTML var txt1="<h1>Tex...

Implementation of mysql split function separated by commas

1: Define a stored procedure to separate strings ...

Why MySQL does not recommend deleting data

Table of contents Preface InnoDB storage architec...

Graphical explanation of the underlying principle of JavaScript scope chain

Table of contents Preface Scope 1. What is scope?...

Detailed installation tutorial of Docker under CentOS

Docker is divided into CE and EE. The CE version ...

Specific use of MySQL segmentation function substring()

There are four main MySQL string interception fun...

HTML simple web form creation example introduction

<input> is used to collect user information ...

Implementing a shopping cart with native JavaScript

This article shares the specific code of JavaScri...

Detailed explanation of jQuery's copy object

<!DOCTYPE html> <html lang="en"...