Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL 5.7 how to choose root password after mysqld --initialize

If I do "mysqld --initialize-insecure", it will be fine with login after initialization, but if I omit "insecure", that will be secure initialization, after which I need a password to login, but I haven't set any password yet.

The menu data-directory-initialization-mysqld indicates that "Regardless of platform, use --initialize for “secure by default” installation (that is, including generation of a random initial root password). In this case, the password is marked as expired and you will need to choose a new one."

I thought that would be the problem, that mysql initializes the super administrative account "root" with a "random password" and "marked as expired", I need to "choose a new one", but how?

Should I try mysqld --initialize -p 'mypassword' or should I type some other prompt clause after initialization?

This problem really bothers me(for twice, I gave up last time after a long time solution searching), indeed I do not need a secure mode to serve data just for testing my app locally, but I'd like to know how to initialize a secure root account for further usages.

I am not sure what I am missing after reading the manu and google it for 4 hours , again.

Thank you.

like image 983
Fadeoc Khaos Avatar asked Mar 10 '18 04:03

Fadeoc Khaos


People also ask

How set MySQL root password after installation?

Use the following procedure to set a root password. To change the root password, type the following at the MySQL/MariaDB command prompt: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.

What is the initial MySQL root password?

The default user for MySQL is root and by default it has no password.


1 Answers

You simply logged in with the root user and the given password which was generated when you use the --initialize option. From https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization.html#data-directory-initialization-server-actions:

With --initialize but not --initialize-insecure, the server generates a random password, marks it as expired, and writes a message displaying the password:

[Warning] A temporary password is generated for root@localhost:
iTag*AfrH5ej

When you logged in you can change the password with ALTER USER. Still from https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization.html#data-directory-initialization-password-assignment:

  1. Start the server. For instructions, see Section 2.10.2, “Starting the Server”.

  2. Connect to the server:

    [...]

  3. After connecting, assign a new root password:

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

like image 79
Progman Avatar answered Oct 16 '22 01:10

Progman