O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using init-file

On Unix-like systems, you stop the server and start it by specifying init-file. You can save the ALTER USER 'root'@'localhost' IDENTIFIED BY 'New$trongPass1'  SQL code in that file. MySQL executes the contents of the file at startup, changing the password of the root user:

  1. Stop the server:
shell> sudo systemctl stop mysqldshell> pgrep mysqld
  1. Save the SQL code in /var/lib/mysql/mysql-init-password; make it readable to MySQL only:
shell> vi /var/lib/mysql/mysql-init-passwordALTER USER 'root'@'localhost' IDENTIFIED BY 'New$trongPass1';shell> sudo chmod 400 /var/lib/mysql/mysql-init-passwordshell> sudo chown mysql:mysql /var/lib/mysql/mysql-init-password
  1. Start the MySQL server with the --init-file option and other options ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required