Databases 29 min read

Master MySQL 8.0.28: Install, Configure, and Connect via JDBC

This guide walks beginners through downloading, installing, and configuring MySQL 8.0.28 on Windows and Linux, covering environment variables, service management, password recovery, user and role creation, and JDBC connection setup with Maven, providing detailed commands, code snippets, and troubleshooting tips for a complete setup.

dbaplus Community
dbaplus Community
dbaplus Community
Master MySQL 8.0.28: Install, Configure, and Connect via JDBC

Download MySQL 8.0.28

Obtain the community edition from the official MySQL download page (e.g., https://dev.mysql.com/downloads/mysql/). Choose the MSI installer for Windows or the ZIP archive for manual setup. For Linux, download the RPM bundle appropriate for the target distribution (e.g., EL7).

Windows installation (ZIP method)

1. Set environment variable

# Variable name
MySQL_HOME
# Variable value
D:\work\mysql-8.0.28-winx64\bin

2. Create my.ini

Place the file in the extracted directory with the following content (adjust paths as needed):

[client]
default-character-set=utf8

[mysqld]
port=3307
basedir=D:\work\mysql-8.0.28-winx64
 datadir=D:\work\mysql-8.0.28-winx64\data
max_connections=20
character-set-server=utf8
default-storage-engine=INNODB

3. Initialise data directory

# Open an administrator command prompt and change to the bin directory
cd D:\work\mysql-8.0.28-winx64\bin

# Initialise with an empty root password
mysqld --initialize-insecure

4. Install the service

# Install with the default service name (MySQL)
mysqld install
# Or specify a custom name
mysqld install mysql8

5. Service management

# Start the service
net start mysql   # or net start mysql8
# Stop the service
net stop mysql    # or net stop mysql8
# Remove the service
sc delete mysql   # or mysqld remove mysql8

6. Password recovery (root password forgotten)

On Windows, add skip-grant-tables to the [mysqld] section of my.ini, restart the service, then reset the password:

mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
FLUSH PRIVILEGES;

Linux installation (RPM bundle)

1. Remove conflicting MariaDB libraries

yum remove mariadb-libs

2. Install required RPM packages (example for EL7)

rpm -ivh mysql-community-data-files-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm

3. Initialise the data directory

mysqld --initialize-insecure

4. Start and enable the service

systemctl start mysqld
systemctl enable mysqld

5. Configure firewall (open default MySQL port 3306)

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

User and role management (MySQL 8.0)

MySQL 8.0 supports role‑based access control.

# Create roles
CREATE ROLE 'app_developer', 'app_read', 'app_write';

# Grant privileges to roles
GRANT ALL ON app_db.* TO 'app_developer';
GRANT SELECT ON app_db.* TO 'app_read';
GRANT INSERT, UPDATE, DELETE ON app_db.* TO 'app_write';

# Create a user and assign a role
CREATE USER 'dev1'@'localhost' IDENTIFIED BY 'dev1pass';
GRANT 'app_developer' TO 'dev1'@'localhost';

# Lock a user account
ALTER USER 'old_app_dev'@'localhost' ACCOUNT LOCK;

JDBC integration

1. Maven dependency for MySQL Connector/J 8.0.28

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.28</version>
</dependency>

2. Sample Java program using plain JDBC

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestConnMySQL8 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://192.168.245.147:3306/TEST?useUnicode=true&characterEncoding=utf-8";
        String username = "root";
        String password = "Mysql@123456";
        try (Connection conn = DriverManager.getConnection(url, username, password);
             PreparedStatement ps = conn.prepareStatement("SELECT * FROM STUDY");
             ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                System.out.println("ID:" + rs.getInt("ID"));
                System.out.println("Name:" + rs.getString("NAMES"));
            }
        }
    }
}

Basic SQL workflow (example schema)

# Create database and use it
CREATE DATABASE TEST;
USE TEST;

# Create a simple table
CREATE TABLE STUDY (
    ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    NAMES VARCHAR(64) NOT NULL
) ENGINE=InnoDB;

# Insert a row
INSERT INTO STUDY VALUES (1, 'mysql 8.0.28 demo');

# Query the table
SELECT * FROM STUDY;

# Update a row
UPDATE STUDY SET NAMES='Updated text' WHERE ID=1;

# Delete all rows
DELETE FROM STUDY;

Reference URLs (plain text)

MySQL download page: https://dev.mysql.com/downloads/mysql/

MySQL 8.0 reference manual: https://dev.mysql.com/doc/refman/8.0/en/

Connector/J installation guide: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-installing-maven.html

Role management documentation: https://dev.mysql.com/doc/refman/8.0/en/roles.html

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseConfigurationLinuxmysqlJDBCWindowsInstallation
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.