[MySQL Notes] Windows uses compressed packages to install MySQL database services

This article mainly introduces how to install MySQL database service in Windows using compressed package.

Table of contents

1. Install MySQL in compressed package

1.1. Download MySQL

1.2. Install MySQL

(1) Add my.ini configuration file

(2) Initialize the database

(3) Install mysql service

(4) Start mysql service

(5) Stop mysql service

(6) Uninstall mysql service

1.3. Modify password

(1) connect to mysql

(2) Initialize the password of the root user

1.4. Navicat connects to mysql


1. Install MySQL in compressed package

1.1. Download MySQL

First, go to the MySQL official website to download a compressed package, you can install MySQL8.x or MySQL5.x version, this article I use MySQL 5.x version as an example.

https://downloads.mysql.com/archives/community/

1.2. Install MySQL

Unzip the downloaded MySQL compressed package to a directory, and then create a [my.ini] configuration file in the installation directory.

(1) Add my.ini configuration file

In the [my.ini] configuration file, add the following content:

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口,也可以自定义端口
port=3306
# 设置mysql的安装目录,这里使用【\\】双斜杠
basedir=E:\\softwares\\mysql5.7
# 设置mysql数据库的数据的存放目录,data目录不需要自己创建,初始化时候会自动创建
datadir=E:\\softwares\\mysql5.7\\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 跳过权限表,可以不需要密码就可以登录mysql
skip-grant-tables

(2) Initialize the database

Open the CMD command prompt window as an administrator ( note: use the command prompt instead of Windows Powershell ), remember to be an administrator, otherwise when you execute some commands later, you will be prompted that you do not have permission to enter the mysql installation directory [bin] directory, and then execute the following command to initialize the MySQL database service.

# 初始化mysql服务
mysqld --initialize

After successful execution, it looks like this:

(3) Install mysql service

In the [bin] directory, execute the install command to install the mysql service.

# 安装mysql服务,安装成功后,会创建data目录
mysqld install

The running results are as follows:

(4) Start mysql service

Execute the [net start mysql] command to start the mysql service.

# 启动mysql服务
net start mysql

(5) Stop mysql service

Execute the [net stop mysql] command to stop the mysql service.

# 停止mysql服务
net stop mysql

(6) Uninstall mysql service

Execute the [mysqld --remove mysql] command to uninstall the mysql service.

# 卸载mysql服务
mysqld --remove mysql

1.3. Modify password

(1) connect to mysql

In the bin directory, enter the [mysql -uroot -p] command, press Enter, and prompt you to enter the password, just press Enter.

(2) Initialize the password of the root user

# 使用mysql数据库
user mysql;
# 更新root用户的密码
update MySQL.user set authentication_string=password('root') where user='root';
# 刷新权限
flush privileges;

As follows:

At this point, the password of the root user has been modified, and finally the [skip-grant-tables] attribute in the my.ini configuration file is commented out .

1.4. Navicat connects to mysql

When using Navicat to connect to the mysql service, if the [Your password has expired] error message is displayed, as shown below:

If the above error occurs, you need to execute the following two commands at this time:

# 设置root用户的密码
set password for root@localhost = password('root');
# 设置密码永不过期
alter user `root`@`localhost` password expire never;

As shown below:

Navicat connects to the mysql service again, and the connection is successful at this time.

At this point, the Windows installation of the MySQL database is complete.

To sum up, this article is over. It mainly introduces how to install MySQL database service in Windows using compressed package.

Guess you like

Origin blog.csdn.net/qq_39826207/article/details/129697552