Skip to content

Instantly share code, notes, and snippets.

@bantya
Created October 16, 2019 11:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bantya/3373fac948d26e74c7233e6024f71459 to your computer and use it in GitHub Desktop.
Save bantya/3373fac948d26e74c7233e6024f71459 to your computer and use it in GitHub Desktop.
Setup MySQL 8
  1. Install MySQL-8.0 from here.

  2. Open Terminal and go to /MySQL-8.0/bin directory.

  3. Run mysqld --initialize.

    This will initialize the mysql data directory at location specified in /MySQL-8.0/my.ini file; if not, it will initialize the data directory inside /MySQL-8.0/data.

  4. Run mysqld --console command.

    This command will start the mysql server in console mode.

  5. 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'.

  6. Now go to the data directory created during initialization in step 3.

    Open the [YOUR_WINDOWS/MAC/LINUX_USERNAME].err file 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.

  7. 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>
    
  8. 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.

  9. To stop the server, enter mysqladmin -u root -p shutdown.

    Enter your new password when asked and done!

  10. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment