MySQL 8.0 Detailed Installation and Configuration Tutorial

I. Introduction

MySQL is currently the most popular open source database product, and it is a fully networked cross-platform relational database system. It was originally developed by the Swedish MySQLAB company, was later acquired by Oracle Corporation, and currently belongs to Oracle Corporation. Because of open source, anyone can download MySQL software from the official website for free, and "open source" means that anyone can use and modify the software, so MySQL database is also widely used in enterprise-level project development.

The first database product that most students who learn Java come into contact with is the MySQL database. Many students often crash the MySQL database due to improper use during the learning process. The reason is often caused by online brainless installation when installing MySQL. The installation process of MySQL is unknown, and the configuration file is modified at will later, and the file directory is changed or moved.

Brother Yang will install and configure MySQL manually today, and explain to you the environmental requirements of MySQL runtime, so as to avoid some students from repeating the same mistakes.

2. MySQL software download

There are two types of MySQL software: one is the online installation version with the suffix .msi; the other ends with .zip. Brother Yang recommends that you use the .zip compressed package. This time, we choose the latest version of MySQL-8.0.30 from the official website to download.

2.1 MySQL installation package download

Software download link: https://dev.mysql.com/downloads/mysql/

image.png

Note: If you are visiting this official website for the first time, you need to register an account before downloading. To register a new account, fill in the personal information according to the prompts, and submit it correctly, so there is no more nonsense here.

Of course, if you find it troublesome and don’t want to register, you can also click the link to download directly as shown in the picture below.

image.png

2.2 Download other versions of MySQL

3. MySQL installation and configuration

3.1 Decompress the MySQL compressed package

After the software download is complete, find a directory to decompress. Brother Yang, here is to put it in the directory you want to install, for example: D:\apps\mysql80\mysql-8.0.30-winx64

image.png

3.2 Create database file directory

Create an empty data folder under the MySQL main directory as the storage directory for data files.

Note: This directory will be used in the next step of configuration.

3.3 Create and modify the configuration file my.ini

Create a configuration file named my.ini in the MySQL main directory with the following content:

[mysql]
#设置mysql数据库客户端默认字符集
default-character-set=UTF8
[mysqld]
#设置mysql数据库默认端口号,注意端口号不能被占用
port=3316
#设置记录日志的显示时间
log_timestamps=SYSTEM
#设置mysql安装目录
basedir=D:\\apps\\mysql80\\mysql-8.0.30-winx64
#设置mysql数据库的数据存放目录
datadir=D:\\apps\\mysql80\\mysql-8.0.30-winx64\\data
#设置mysql数据库服务端默认字符集
character-set-server=UTF8
#设置mysql数据库创建新表时的默认存储引擎
default-storage-engine=INNODB
#设置mysql数据库允许的最大链接数
max_connections=100

3.4 Add environment variables

"Create" a variable named "MYSQL_HOME" in the system environment variables. Variable value: "D:\apps\mysql80\mysql-8.0.30-winx64"

Edit the existing environment variable "Path" and add "%MYSQL_HOME%\bin" at the end.

3.5 Initialize MySQL service

Run cmd as an administrator, enter the bin directory, and execute the mysqld --initialize-insecure --user=root command. If this step is not performed, the service will fail to start after the installation is complete.

After MySQL is initialized, some data will be generated under the directory data

4. Add MySQL to system services

4.1 Install and start the service

Still in the bin directory of the administrator cmd window, execute the > mysqld -install MySQL command to install. After completion, it will prompt that the installation is successful.

4.2 Delete service

To delete a service, execute the following command:

mysqld -remove mysql

Notice:

Before deleting the service, the service must be terminated first (execute command: net stop service name)

5. Other maintenance operations

5.1 Initial login

Still in the bin directory of the administrator cmd window, execute the net start MySQL8 command to start the MySQL service.

In the normal cmd window, enter the bin directory, execute the mysql -u root -p command, there is no password by default, press Enter to enter;

The default port of mysql service is 3306, if the port of mysql service is not 3306, you need -P port parameter  

5.2 Modify login password

alter user 'root'@'localhost' identified by 'new password';

image.png

5.3 Verify login

Use the quit command to log out of the current login, and then log in to the service with the modified password, as shown in the following figure:

image.png

6. Conclusion

Finally, Brother Yang would like to remind everyone that many beginners like to organize information during the learning process, and accidentally modify or remove the software directory. This does not match the configuration information of the system environment variables, and it will also cause the MySQL service to start. fail. Must remember here! Remember!

Now you know how to install and configure MySQL database? If you have other questions, you can leave us a message in the comment area.

Qianfeng Education Java Introduction Full Set of Video Tutorials (java core technology, suitable for java zero foundation, necessary for self-study of Java)

Guess you like

Origin blog.csdn.net/longz_org_cn/article/details/131973930