How to install and start MySql on Windows

1. MySql installation package download

First enter the following website, select the appropriate version to download.

https://dev.mysql.com/downloads/mysql/

Here we choose the 64-bit installation package of the windows version. If you need the linux version, please replace it yourself.

20221203001318

20221203004802

No need to log in, click "No thanks, just start my download." to start downloading directly

After the download is complete, unzip it to your favorite directory. Here my directory is:
D:\DB\mysql-8.0.31-winx64\

Two, MySql initialization

The executable program is located in the bin directory. We open the cmd console as an administrator , enter the bin directory, and execute the following command to initialize MySql

mysqld --initialize --console

20221203001657

After the initialization command is executed, the console will print out the initial password of the root user, see the red box above, remember this password, it will be used later.

After initialization, we execute the following command to install the mysqld service.

mysqld --install

20221203002018

3. Start the MySql service

Execute the following command to start the mysql service.

net start mysql

20221203002155

You can see the words that the startup was successful.

4. Login to MySql

Remember to start the MySql service before logging in to MySql.

Use the following command to log in, the password is the random password generated during the previous initialization:

mysql -uroot -p

20221203002644

As shown in the figure, you can log in successfully. Note that this step is performed on the server. The server here is our local computer.

Five, modify the root password of MySql

This step is optional, but the random passwords generated before are messy and hard to remember, so we change them to our own passwords.

alter user 'root'@'localhost' identified by '123456';

Note that it is executed on the mysql command line at this time, and a semicolon is required at the end of the command.
20221203003104

After quitting, use the new password to log in again to verify whether the modification is successful.

20221203003210

6. About remote login

Usually, if MySql is used as a server, it is usually installed on a specific remote host, such as a linux server, which has its own ip and host name. If we want to log in on the local computer (as a client), we need to specify the host name or ip address in the login command, for example:

mysql -uroot -p -h127.0.0.1 -P3306

参数 -h 指定主机
参数 -P 指定端口

Seven, set environment variables

You can add the MySql bin to the local environment variable, so that you don’t need to bring a long path every time you execute the command, which is much more convenient.

Right-click My Computer, click Properties, find Advanced System Settings, and click Environment Variables

20221203022519

20221203022634

Double-click Path, create a new entry, and add the directory where the mysql executable file is located to Path.

20221203022718

20221203022904

Now you can directly execute the mysql command in any directory

20221203023008

Guess you like

Origin blog.csdn.net/hubing_hust/article/details/128156846