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

Use jQuery to fix the invalid page anchor point problem under iframe

The application scenario is: the iframe page has n...

Markup language - for

Click here to return to the 123WORDPRESS.COM HTML ...

How to add a certificate to docker

1. Upgrade process: sudo apt-get update Problems ...

HTML Tutorial: Ordered Lists

<br />Original text: http://andymao.com/andy...

Pure CSS to achieve three-dimensional picture placement effect example code

1. Percentage basis for element width/height/padd...

CentOS7 deploys version 19 of docker (simple, you can follow it)

1. Install dependency packages [root@localhost ~]...

Tips for making web table frames

<br />Tips for making web table frames. ----...

JavaScript implements the nine-grid mobile puzzle game

This article shares the specific code for JavaScr...

How to query the minimum available id value in the Mysql table

Today, when I was looking at the laboratory proje...

Steps to deploy ingress-nginx on k8s

Table of contents Preface 1. Deployment and Confi...

Detailed explanation of Bootstrap grid vertical and horizontal alignment

Table of contents 1. Bootstrap Grid Layout 2. Ver...

CSS code to achieve background gradient and automatic full screen

CSS issues about background gradient and automati...

Introduction and use of five controllers in K8S

Table of contents Controller type of k8s Relation...