Table of Contents
1, Installation
Execute the command in the
(需要注意:mysql8.0加密方式修改了)
检查用户
授权所有权限
授权基本的查询修改权限,按需求设置
Home Database Mysql Tutorial Comprehensive explanation of the installation method of MySQL8.0 For Windows

Comprehensive explanation of the installation method of MySQL8.0 For Windows

Oct 25, 2021 pm 04:26 PM
mysql

Download the zip installation package:

 MySQL8.0 For Windows zipPackage download address: https://dev.mysql.com/downloa..., you don’t need to log in after entering the page. Then click "No thanks, just start my download." at the bottom to start downloading.

Or download directly: https://dev.mysql.com/get/Dow...

Environment: Windows 10

1, Installation

 1.1. Unzip the zip package to the installation directory
For example, my installation directory is: C:\Program Files\MySQL

 1.2. Configuration file
In the Windows system, the configuration file defaults to the my.ini file (or my-default.ini) in the installation directory. Some configurations need to be initialized Configured during installation, most can also be changed after installation is complete. Of course, in extreme cases, everything can be changed.

We found that the decompressed directory does not have the my.ini file. It doesn’t matter, you can create it yourself. Add my.ini in the installation root directory, for example, here is: C:\Program Files\MySQL\my.ini, write the basic configuration:

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=C:\Program Files\MySQL
# 设置mysql数据库的数据的存放目录
datadir=E:\database\MySQL\Data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
Copy after login

Note, the # inside ##basedir is my local installation directory, datadir is the location where my database data files are stored. Each configuration needs to be configured according to your own environment.

To view all configuration items, please refer to: https://dev.mysql.com/doc/ref...

 

1.3, initialize the database Execute the command in the
bin directory of the MySQL installation directory:

mysqld --initialize --console

Execute After completion, the initial default password of the

root user will be printed, such as:

C:\Users\Administrator>cd C:\Program Files\MySQL\bin

C:\Program Files\MySQL\bin>mysqld --initialize --console
2018-04-28T15:57:17.087519Z 0 [System] [MY-013169] [Server] C:\Program Files\MySQL\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 4984
2018-04-28T15:57:24.859249Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rI5rvf5x5G,E
2018-04-28T15:57:27.106660Z 0 [System] [MY-013170] [Server] C:\Program Files\MySQL\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed

C:\Program Files\MySQL\bin>
Copy after login
Attention! There is a paragraph in the execution output result:

[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rI5rvf5x5G,E where root@localhost: follows "rI5rvf5x5G,E" is the initial password (excluding the first space). Before changing the password, you need to remember this password and use it for subsequent logins.

If you are stupid, shut down too quickly, or don’t remember it, it’s okay. Delete the initialized

datadir directory, execute the initialization command again, and it will be regenerated. Of course, you can also use security tools to force a password change. It’s up to you which method you use.

Reference: https://dev.mysql.com/doc/ref...

1.4, install the service

in the
MySQL installation directory## Execute the command in the #bin directory (open the cmd command line as an administrator, or right-click on the installation directory Shift and "Open a command line window here" ):

mysqld --install [Service name] The service name following

does not need to be written. The default name is

mysql

. Of course, if you need to install multiple MySQL services on your computer, you can use different names to distinguish them, such as mysql5 and mysql8. After the installation is completed, you can start the

MySQL

service through the command net start mysql. Example:

C:\Program Files\MySQL\bin>mysqld --install
Service successfully installed.

C:\Program Files\MySQL\bin>net start mysql
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。


C:\Program Files\MySQL\bin>
Copy after login

Reference: https://dev.mysql.com/doc/ref...

Second, change password and password authentication plug-in

Execute the command in the

bin

directory of the MySQL installation directory:

mysql -u root -p

At this time, it will You will be prompted to enter a password. Remember the password used during installation in step 1.3 above. Fill it in and you will be able to log in successfully and enter the MySQL command mode.
Before

MySQL8.0.4

, execute

SET PASSWORD=PASSWORD('[modified password]');

Change the password, but starting from MySQL8.0.4
, this will not work by default. Because before, the password authentication plug-in for MySQL was "mysql_native_password", but now it is "caching_sha2_password". Because many database tools and link packages currently do not support

"caching_sha2_password"

, for the sake of convenience, I temporarily changed it back to the "mysql_native_password" authentication plug-in. Change the user password and execute the command in

MySQL

:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new password';

Modify the password verification plug-in and change the password at the same time.
If you want to use

"mysql_native_password"

plug-in authentication by default, you can configure the default_authentication_plugin item in the configuration file.

[mysqld]

default_authentication_plugin=mysql_native_password
Example:

C:\Program Files\MySQL\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
Query OK, 0 rows affected (0.06 sec)

mysql>
Copy after login

Copy code

Reference: https://dev.mysql.com/doc/ref...

At this point, the installation and deployment is complete. Officially, the test speed

MySQL8

is twice as fast as 5. You can use the command to check the default installed database:

show databases;

use mysql;

show tables;
Copy after login
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql>
Copy after login

看到默认初始化了mysql数据库,其中user表里面存储MySQL用户信息。我们可以看一下默认MySQL用户:

select user,host,authentication_string from mysql.user;

mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+-------------------------------------------+
| user             | host      | authentication_string                     |
+------------------+-----------+-------------------------------------------+
| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.session    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys        | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root             | localhost | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
+------------------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)

mysql>
Copy after login

管理员roothostlocalhost,代表仅限localhost登录访问。如果要允许开放其他ip登录,则需要添加新的host。如果要允许所有ip访问,可以直接修改成“%”

创建用户:

CREATE USER 'xxh'@'%' IDENTIFIED WITH mysql_native_password BY 'xxh123!@#';

(需要注意:mysql8.0加密方式修改了)

检查用户

select user, host, plugin, authentication_string from user\G;

授权远程数据库

授权所有权限

GRANT ALL PRIVILEGES ON *.* TO 'xxh'@'%';

授权基本的查询修改权限,按需求设置

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'xxh'@'%';

查看用户权限
show grants for 'xxh'@'%';

示例:

mysql> use mysql;
Database changed
mysql> CREATE USER 'xxh'@'%' IDENTIFIED WITH mysql_native_password BY 'xxh123!@#'; #创建用户(注意:mysql8.0加密方式修改了)
Query OK, 0 rows affected (0.07 sec)
mysql>
Copy after login

查看密码加密方式:

mysql> select user, host, plugin, authentication_string from user;
+------------------+-----------+-----------------------+-------------------------------------------+
| user             | host      | plugin                | authentication_string                     |
+------------------+-----------+-----------------------+-------------------------------------------+
| xxh              | %         | mysql_native_password | *70FD6FB4F675E08FF785A754755B5EBA6DA62851 |
| mysql.infoschema | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.session    | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys        | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root             | localhost | mysql_native_password | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
+------------------+-----------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)

mysql>
Copy after login

另外,如果需要新增账户,或者本机以外的其他人访问MySQL则还需要设置内置账户的host,具体可以参考:MySQL创建用户与授权。

推荐学习:《mysql视频教程

The above is the detailed content of Comprehensive explanation of the installation method of MySQL8.0 For Windows. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

The difference between oracle database and mysql The difference between oracle database and mysql May 10, 2024 am 01:54 AM

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

See all articles