Installing MySQL 5.7 on Windows and Changing the Root Password

Downloading MySQL 5.7

Begin by downloading the MySQL 5.7 installer from the official MySQL Community Downloads archive. Navigate to the following URL and select a version from the 5.7.x series.

https://downloads.mysql.com/archives/community/

Manual Installation Steps

2.1 Extracting and Configuring Environment Variables

After downloading the archive, extract its contents to a dedicated directory on your system drive, for example, C:\mysql\mysql-5.7.38-winx64.

Next, add the path to the bin subdirectory (e.g., C:\mysql\mysql-5.7.38-winx64\bin) to your system's PATH environment variable. This allows you to run MySQL commands from any command prompt.

2.2 Creating Necessary Directories and Configuration File

The extracted package does not include the required data and uploads directories, nor the my.ini configuration file. You must create these manually within the main MySQL directory.

  • Create a data folder inside C:\mysql\mysql-5.7.38-winx64.
  • Create an uploads folder inside C:\mysql\mysql-5.7.38-winx64.
  • Create a new file named my.ini in the root directory C:\mysql\mysql-5.7.38-winx64.

Open the my.ini file in a text editor and add the following configuration. Ensure the paths for basedir, datadir, and secure-file-priv match your installation directory.

[mysql]
default-character-set=utf8

[mysqld]
port=3306
character_set_server=utf8
basedir=C:\mysql\mysql-5.7.38-winx64
datadir=C:\mysql\mysql-5.7.38-winx64\data
server-id=1
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
innodb_file_per_table = 1
log_timestamps=SYSTEM

log-error   = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 5
log-bin = binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
secure-file-priv=C:\mysql\mysql-5.7.38-winx64\uploads

[client]
port=3306
default-character-set=utf8

2.3 Initializing, Registering, and Starting the Data base

Open a Command Prompt with administrative privileges. Use the following commands to initialize the database, install it as a Windows service, and then start the service.

mysqld --initialize-insecure
mysqld --install MySQL57
net start MySQL57

Changing the Root Password

3.1 Finding the Initial Root Password

For versions initialized with --initialize-insecure, the root password is empty. If you used --initialize, the password is generated and logged. In that case, locate the error.log file within the data directory and search for the string "A temporary password is generated". The pasword will be displayed next to it.

3.2 Logging in to MySQL

Using the Command Prompt, log in to the MySQL server. If you used --initialize-insecure, you can log in without a password. Otherwise, use the temporary password found in the previous step.

mysql -u root -p

3.3 Setting a New Root Passworrd

Once logged in, execute the following SQL command to change the root password to a secure value of your choice, for example, MyNewPass123!. Replace this with your desired password.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass123!';
FLUSH PRIVILEGES;
EXIT;

Tags: MySQL Windows Database Administration

Posted on Tue, 22 Sep 2026 16:40:49 +0000 by jalapena