MySQL is an open source relational database management system. It is widely used in various types of applications including websites, e-commerce, blogs, and more. This article will focus on how to install MySQL through the command line in the Windows operating system.
Before starting the installation, you need to download the appropriate installation package from the MySQL official website. We can find the MySQL installation package that suits us on the download page of the mysql.com website. Select the corresponding version according to your needs, and then download it to the local disk.
After the download is complete, we need to decompress the installation package into an appropriate directory. Here, we unzip the installation package into the D:\mysql directory.
To install MySQL from the command line, you need to configure the environment variables first. We need to add the MySQL installation path to the system environment variable so that MySQL commands can be used at any time. In the Windows system, open "My Computer" -> "Right-click Properties" -> "Advanced System Settings" -> "Environment Variables", find Path in the system variables, and then add the installation path of MySQL, which is D :\mysql\bin.
To install MySQL in the command line, you first need to open the command line. Right-click the Start menu and select Command Line Prompt.
Enter the following command on the command line:
cd D:\mysql\bin
This will switch the current directory to the MySQL bin directory.
Next, enter the following command to start the MySQL installation:
mysqld install
After successful execution, you can see the following prompt:
Service successfully installed.
Next, we need to start the MySQL service. In the command line, enter the following command:
net start MySQL
After successful execution, we can get the following prompt:
The MySQL service is starting The MySQL service was started successfully.
That is, the MySQL service has been started successfully.
The default installation account for MySQL is root, and the default password is empty. To ensure security, we need to change the password of the root user.
First, we need to enter the MySQL command line interface. Enter the following command at the command line:
mysql -u root -p
This will prompt us for a password. Since we have not set a password, we can just press Enter.
Next, enter the following command:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
This will change the password of the root user to "MyNewPass". We can change the password according to our needs.
After the installation is complete, we can test whether MySQL can be used normally through the command line. Enter the following command at the command line:
mysql -u root -p
This will prompt us for a password. Enter the password we just set and press Enter.
If everything is normal, we should be able to see information similar to the following:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.7.24 MySQL Community Server (GPL) ...
At this point, the installation of MySQL under the Windows command line is complete. Installing MySQL in this way saves computer resources to a certain extent and also improves MySQL operating efficiency, which is suitable for users with high performance requirements.
The above is the detailed content of How to install MySQL through the command line. For more information, please follow other related articles on the PHP Chinese website!