You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ssh root@IP
sudo apt update && sudo apt upgrade -y
sudo apt install mariadb-server -y
sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation
sudo mariadb
CREATE USER 'USER'@'%' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'USER'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
sudo ufw allow 3306
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
# FIND THIS LINE:# bind-address = 127.0.0.1# CHANGE TO:# bind-address = 0.0.0.0# RESTART MARIADB
sudo systemctl restart mariadb
MySQL Database Structure (Anxhelo)
CREATEDATABASEIF NOT EXISTS MySql_Exercise_Andri_Anxhelo;
USE MySql_Exercise_Andri_Anxhelo;
CREATETABLEIF NOT EXISTS books(
bookid int auto_increment primary key,
title varchar(255),
pages_length int,
author varchar(255)
);
INSERT INTO books(title, pages_length, author) VALUES
('To Kill a Mockingbird', 281, 'Harper Lee'),
('The Great Gatsby', 180, 'F. Scott Fitzgerald'),
('Moby-Dick', 635, 'Herman Melville'),
('Pride and Prejudice', 432, 'Jane Austen'),
('War and Peace', 1225, 'Leo Tolstoy');
Java Database Connector (Anxhelo)
##JavaDatabaseConnectorimportjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.Statement;
/** * A simple Java example demonstrating how to connect to a MySQL database, * execute a SELECT query, and display results from the 'books' table. * * This example connects to a database using JDBC and prints book details. */publicclassMySQLExample {
/** * Main method that initiates the database connection and queries the 'books' table. * * @param args command-line arguments (not used) */publicstaticvoidmain(String[] args) {
// JDBC URL, username and password for the database connectionStringurl = "jdbc:mysql://64.226.127.206:3306/MySql_Exercise_Andri_Anxhelo";
Stringuser = "anxhelo";
Stringpassword = "1Schueler@";
try {
// Establish the database connectionConnectionconnection = DriverManager.getConnection(url, user, password);
// Create a statement to execute SQL queriesStatementstatement = connection.createStatement();
// SQL query to select all rows from the 'books' tableStringquery = "SELECT * FROM books";
// Execute the query and get the result setResultSetresultSet = statement.executeQuery(query);
// Iterate through the result set and print book detailswhile (resultSet.next()) {
System.out.println("Book ID: " + resultSet.getInt("bookid"));
System.out.println("Title: " + resultSet.getString("title"));
System.out.println("Author: " + resultSet.getString("author"));
System.out.println("Pages: " + resultSet.getInt("pages_length"));
System.out.println();
}
// Close the database connectionconnection.close();
} catch (Exceptione) {
// Print any exceptions that occure.printStackTrace();
}
}
}