If it is not explicitly told in following recipe, setting up services are described for Ubuntu 20.04 server, but applications are described for Xubuntu 20.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

16. JDBC

Review the presentation JDBC

Tasks

Set up MySQL

  1. If needed:
    1. To enable additional software repositories, run

      sudo mousepad /etc/apt/sources.list

      and uncomment the lines that contain # deb... (delete #)

      Do not uncomment # deb cdrom..., otherwise the manager will look for the installation disk!

    2. To refresh the repositories, run the command:

      sudo apt-get update
  2. To install MySQL Servers, run the following command:

    sudo apt-get install mysql-server
  3. Download the MySQL Workbench installation file from https://askubuntu.com/questions/1230752/how-can-i-install-mysql-workbench-on-ubuntu-20-04-lts for 64-bit Ubuntu 20.04.
  4. Open the file and install it.

Set up the database

  1. If necessary, change the values ​​of the variables user, password and database in the TeacherManager.java class and in the src/resources/appplication.properties settings file
  2. Create a new database user by executing the following commands in the terminal (each line one at a time!):

    sudo mysql
    CREATE USER 'u00'@'localhost' IDENTIFIED BY 'u00';
    FLUSH PRIVILEGES;
    exit

    where u00 is the code you provided.

  3. Create the database structure by executing the following commands in the terminal:

    cd ~/workspace/aa00000/src/main/java/jtm/activity16/
    sudo mysql
    create database database00;
    GRANT ALL ON database00.* TO 'u00'@'localhost';
    FLUSH PRIVILEGES;
    exit
    mysql -uu00 -pu00 database00 < database.sql

    where aa00000 is your project name and u00 is the code you were given.

Set up verbose MySQL logging (optional)

To enable verbose logging on your MySQL server:

  1. Open the configuration file:

    sudo mousepad /etc/mysql/mysql.conf.d/mysqld.cnf
  2. Change the two lines to the following (i.e., remove the # from the beginning of the line):

    general_log_file = /var/log/mysql/query.log
    general_log = 1
  3. Restart the mysql server:

    sudo systemctl restart mysql
  4. To view the log in real time, run the command:

    sudo tail -f /var/log/mysql/query.log

Implement the class

  1. Explore the jtm.activity16 package
  2. Implement the TeacherManager class to pass the unit tests

Error Solutions

  1. To check if the server is running:

    ss -ntlp|grep 3306

    should return:

    LISTEN 0 151 127.0.0.1:3306 0.0.0.0:*
    LISTEN 0 70 127.0.0.1:33060 0.0.0.0:*
  2. To check if you can log in to the server, run the MySQL console:

    mysql -uu00 -pu00

    Then in the MySQL console:

    show databases;

    should return the database list.

    exit))

Extra exercises

Additional information

In English

In Latvian


  

Created by Valdis Vītoliņš on 2025-01-28 17:42
Last modified by Valdis Vītoliņš on 2025-01-28 17:43
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License