Home > Database > Mysql Tutorial > body text

How to build a MySQL database on Windows operating system

PHPz
Release: 2023-04-20 11:03:18
Original
3704 people have browsed it

MySQL is an open source relational database management system and the most widely used database in website development.

This article will introduce in detail how to build a MySQL database on the Windows operating system.

1. Preparation

1. Download the MySQL installation file

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

Select the corresponding operating system and version to download. This article takes MySQL 8.0 as an example.

2. Install MySQL

After the download is complete, run the installation program and follow the prompts to install.

2. Configure MySQL

1. Start the MySQL service

During the installation process, the MySQL service will be automatically installed and started. If it does not start automatically, you can manually start the MySQL service in "Services".

In Windows, press Win R, enter services.msc to open the "Services" window.

2. Set up the MySQL administrator account

The MySQL administrator account is used to manage the MySQL database system.

Run cmd or terminal window and enter the following command:

mysql -u root -p
Copy after login

There will be a window prompting you to enter a password. There is no need to enter a password here, just press the Enter key.

After entering the mysql command line, enter the following command to set the administrator account:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
Copy after login

Among them, the new password can be set by yourself.

3. Create a new user

After entering the command line using the administrator account, you can create a new user.

For example, to create a new user named newuser with password password, you can enter the following command:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Copy after login

4. Assign permissions to the new user

The new user is created After that, you need to assign permissions to it.

For example, to give the newuser user access rights to all databases, you can enter the following command:

GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
Copy after login

5. Exit the MySQL command line

In the MySQL command line, enter the following The command can exit:

exit;
Copy after login

3. Test MySQL

After completing the above configuration, you can perform MySQL testing.

1. Open the command line

In Windows, press Win R, enter cmd to open the command line.

2. Connect to MySQL

In the command line, enter the following command to connect to MySQL:

mysql -u newuser -p
Copy after login

Enter the password of newuser and press Enter to connect to MySQL.

3. Create a test database

Enter the following command to create a testdb database:

CREATE DATABASE testdb;
Copy after login

4. Create a test table

Enter the following command to create a table named test_table Table:

USE testdb;
CREATE TABLE test_table (id INT, name VARCHAR(20));
Copy after login

5. Insert data

Enter the following command to insert data into the table:

INSERT INTO test_table VALUES (1, 'Test1');
INSERT INTO test_table VALUES (2, 'Test2');
INSERT INTO test_table VALUES (3, 'Test3');
Copy after login

6. Query data

Enter the following command to query Data in the table:

SELECT * FROM test_table;
Copy after login

The query results should be as follows:

+------+-------+
| id   | name  |
+------+-------+
|    1 | Test1 |
|    2 | Test2 |
|    3 | Test3 |
+------+-------+
Copy after login

At this point, the MySQL test is completed.

Summary:

This article mainly explains the whole process of building a MySQL database on the Windows operating system, and finally completes the MySQL test by creating databases, tables and inserting data. By studying this article, readers can have a deeper understanding of the construction and basic use of MySQL database.

The above is the detailed content of How to build a MySQL database on Windows operating system. 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