-
Install MySQL-8.0 from here.
-
Open Terminal and go to
/MySQL-8.0/bindirectory. -
Run
mysqld --initialize.This will initialize the mysql data directory at location specified in
/MySQL-8.0/my.inifile; if not, it will initialize the data directory inside/MySQL-8.0/data. -
Run
mysqld --consolecommand.This command will start the mysql server in console mode.
-
Now open another Terminal window and run
mysql -u root -h localhost.This will result in error:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)This means, the mysql has set the default password for user 'root'@'localhost'.
-
Now go to the
datadirectory created during initialization in step 3.Open the
[YOUR_WINDOWS/MAC/LINUX_USERNAME].errfile in editor. You will see a note in it:2019-10-16T06:57:26.507532Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: [~12_CHAR_TEMPORARY_PASSWORD]Remeber this password.
-
Now in the same Terminal put
mysql -u root -h localhost -p.In
Enter Password:field, enter the temporary password obtained last step. You will see something like:Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.18 MySQL Community Server - GPL Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> -
To change the password, enter
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '[YOUR_NEW_PASSWORD]';If
Query OK, 0 rows affected ([SOME] sec)is displayed, the password is set successfully. -
To stop the server, enter
mysqladmin -u root -p shutdown.Enter your new password when asked and done!
-
To add mysql service to
Windows Services, launch Terminal with admin privilages.Enter
mysqld --install "MySQL 8.0".To remove mysql service from
Windows Services,Enter
mysqld --remove "MySQL 8.0".
Steps taken from this video.