Installation of MySQL8.0.18 under Windows and database access in LAN

Recently, I have been configuring various environments. This blog mainly introduces the installation of MySQL 8.0.18 version in ZIP compression package in detail, and also introduces how to use one computer to access the MySQL database of another computer in the LAN.

1. Download and decompress MySQL database

Download URL: https://dev.mysql.com/downloads/mysql/
(1) Enter the above URL and select Archives to get the past version.
Insert picture description here
(2) The 8.0.18 version is selected here, and then select the first ZIP Archive and click Download to download.
Insert picture description here
Insert picture description here
(3) Put the downloaded file to the installation path you want, and unzip the file to the current path.
Insert picture description here

Two, MySQL database installation

(1) Configure environment variables: add the bin file of mysql-8.0.18-winx64 to the path environment variable.
Insert picture description here
(2) Create a new file named my.ini in the mysql-8.0.18-winx64 file directory, and then open the file with Notepad.
Insert picture description here
(3) Write the following code into the my.ini file just created, where basedir is the mysql installation directory, and datadir is the mysql database data storage directory. Remember to use "/" or "\\" when writing the path. as the picture shows.

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=E:/0xyl/software/MySQL/mysql-5.6.47-winx64
# 设置mysql数据库的数据的存放目录
datadir=E:/0xyl/software/MySQL/Database
# 允许最大连接数
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

Insert picture description here
(4) Press Win+R to enter cmd, use the cd command to locate the MySQL bin directory, and then enter the command mysqld --initialize --console.
Insert picture description here
(5) After running, a random initial password of the database will be generated. Remember to save it. The password I generated here is g3S:EDq-H6sh.
Insert picture description here
(6) Enter mysqld install to install the mysql service.
Insert picture description here
(7) Enter net start mysql to start the MySQL service.
Insert picture description here
(8) Enter mysql -u root -p, and then enter the randomly generated initial password to complete the login.
Insert picture description here
(9) Enter alter user root@localhost identified by'your password' to modify the initial password.
Insert picture description here
In this way, the zip installation of the MySQL8.0.18 database is complete!

3. Access to MySQL database in LAN

(1) Connect to the local database, view the current database user and corresponding host

use mysql;
select user, host from user;

Insert picture description here
(2) Next, we have two ways to implement other computers in the LAN to access the local database.
1. Change the host of the root user

update user set host='%' where user='root'

Insert picture description here
2. Create a new user and grant permissions

create user 'MyPC'@'192.168.3.6' identified by '你的密码';
grant all on *.* to 'MyPC'@'192.168.3.6' with grant option
flush privileges;

Insert picture description here
3. Check the updated user table, you will find that the above two methods have worked.

select user, host from user

Insert picture description here
(3) Run the console as an administrator, close and restart the mysql service.

net stop mysql
net start mysql

Insert picture description here
Note: It must be run as an administrator, otherwise an error will be reported.
Insert picture description here
(4) Change the firewall settings (if it is a Win10 system, this step is required)
1. Perform the system and security of the control panel, select Windows Defender Firewall, and click Advanced Settings on the left.
Insert picture description here
Insert picture description here
2. Select "Inbound Rules" in the column on the left, and then select "New Rule" in the column on the right.

Insert picture description here
Insert picture description here
3. Select the port in the type of rule to be created, fill in 3306 in the specific local port, and name the rule as mysql to complete the operation.
Insert picture description here
Insert picture description here
Insert picture description here
(5) Next is the moment to witness the miracle! We use another computer to access the mysql database of the newly configured computer.

1. Access as root user
Insert picture description here
2. Access as newly created user
Insert picture description here
3. Connect via Navicat
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/xylbill97/article/details/107155628