How to Install MySQL on Windows?
- Download the archive zipfile from given below directory.
- unzip the file.
- Rename it with ‘mysql’ (for ease of use of the folder in later steps).
After that to set the path for MySQL you will have to follow some steps as follows.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.
Step-1 :Create a new directory –
Create a new directory for data in the cmd prompt. When you will use the database you need a directory, where all your files will be saved. Create a directory called “mysql-files” (you can choose any other name also) to keep all your works.
Create a new directory for data in cmd prompt by using the following steps.
"Search" button ⇒ Enter "cmd" ⇒ Click on "Command Prompt"
here, creating a directory in the Documents folder, you can use the commands after opening the command prompt as follows.
- cd Documents (it will enter into the folder)
- now you can create a directory with the keyword mkdir.
Step-2 :Initialize the database –
- Start a CMD.
- Go to the the path where after renaming as mysql is saved and then go to bin folder using keyword cd filename.
C:Users\Uesrname>cd Documents C:Users\Uesrname\Documents>cd mysql C:Users\Uesrname\Documentsmysql>cd bin C:Users\Uesrname\Documents\mysql\bin>
- Execute the following command in the cmd path of bin in mysql extracted path(i.e. in the path C:Users\Uesrname\Documents\mysql\bin>).
mysqld –console –initialize –basedir=(path of newly created data directory) –datadir=(path of newly created data directory)
- After executing the initialize command, Temporary password will be generated. Don’t forget to note that password.
Step-3 :Adding the directory –
Execute the following command in the command prompt or in the same path as follows.
- Add the newly created data which we named as “mysql-files” in Step1.
mysqld --console --datadir=(path of newly created data directory)
Step-4 :Start the server –
Now open another command prompt without closing the present command prompt (in another cmd window of path bin of MySQL)
- Execute the following command as follows.
mysql -u root -p
- As using it the first time, you need to alter the password (temporary password that you have noted in step-2) when you open the server as follows.
Step-5 :Change the password of user root –
- A last step: As using it the first time, you need to alter the password (as you have used temporary password) when you open the server as follows.
ALTER USER root@localhost IDENTIFIED BY '<Your password>';
Now, Your mysql is ready to use. The above steps was to install and use it at first time.
When using MySQL later everytime, you can follow the 3rd and 4th steps:
- Execute following command as follows.
mysqld –console –datadir=(path of newly created data directory)
- (in another cmd window of path bin of mysql)
Execute following command as follows.
mysql -u root -p