Home > Database > Mysql Tutorial > body text

How to install MySQL through the command line

PHPz
Release: 2023-04-17 17:28:08
Original
2804 people have browsed it

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.

  1. Download the MySQL installation package

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.

  1. Extract the installation package

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.

  1. Configuring MySQL environment variables

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.

  1. Install MySQL

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
Copy after login

This will switch the current directory to the MySQL bin directory.

Next, enter the following command to start the MySQL installation:

mysqld install
Copy after login

After successful execution, you can see the following prompt:

Service successfully installed.
Copy after login

Next, we need to start the MySQL service. In the command line, enter the following command:

net start MySQL
Copy after login

After successful execution, we can get the following prompt:

The MySQL service is starting
The MySQL service was started successfully.
Copy after login

That is, the MySQL service has been started successfully.

  1. Modify MySQL default account password

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
Copy after login
Copy after login

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';
Copy after login

This will change the password of the root user to "MyNewPass". We can change the password according to our needs.

  1. Test MySQL

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
Copy after login
Copy after login

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)
...
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template