Accessing MariaDB on NetBeans 8.2 using JDBC, Part 1: Install Employees sample database and grant permission

This entry is part 1 of 3 in the series Accessing MariaDB on NetBeans 8.2 using JDBC

This series shows how to access MariaDB on NetBeans 8.2 using MySQL Connector/J 8.0 on Windows.

I’ll divide into 3 parts:

  1. Part 1: Install Employees sample database and grant permission
    This part, which you’re reading, shows how to install sample database, Employees, on MariaDB.
  2. Part 2: Create a connection
    This part shows how to establish a connection between NetBeans and MariaDB.
  3. Part 3: Perform SQL Operations
    This part show how to perform basic operations from NetBeans to MariaDB. For instance, send querys as SELECT, INSERT, UPDATE to a database.

In this post, I’ve just installed MariaDB 10.1.34 using XAMPP, but there isn’t any sample database installed so I will install sample Employees database before making connection from NetBeans.

Part 1: Install Employees sample database and grant permission

  1. Download Employees sample database from github:
    1. Open web browser to https://github.com/datacharmer/test_db
    2. Click Clone or download
    3. Select Download ZIP

    Download Employees sample database from github.com

  2. Extract zip file on the database server. In this example, I extract to c:\test_db.
    Extract ZIP file
  3. Locate where mysql executable is. In this example, it is installed by XAMPP and the default path is c:\xampp\mysql\bin\mysql.exe
    Locate mysql executable
  4. Open command prompt by right-click Windows icon at bottom left and select Command Prompt
  5. Navigate to the folder where you extract the zip file and type this command:
    c:\xampp\mysql\bin\mysql -u root -p -t < employees.sql

    Parameter explanation:

    • c:\xampp\mysql\bin\mysql – replace this path to mysql executable if you have installed it in different folder.
    • -u root – this is the username for logging-in to the database server.

    Import Employees sample database

  6. Enter password for the username and press Enter.
    If you typed the command correctly, you will see the output similar to this figure which indicates that it’s importing the sample database.
    Importing Employees sample database
  7. Next, let’s create a new user and grant permission for the database. Login to mysql server by type this command. You should see text “MariaDB” at left if you have successfully login.
    c:\xampp\mysql\bin\mysql -u root -p

    Login to MySQL server

  8. Type this command to list all databases. You should have the database employees in the list.
    SHOW DATABASES;

    List databases on the MySQL server

  9. Create a new user “user_employees” with password “mypassword1234” with this command.
    CREATE USER 'user_employees' IDENTIFIED BY 'mypassword1234';

    Create a new user

  10. Grant all permissions for “user_employees” to employees database by type this command.
    GRANT ALL ON employees.* TO 'user_employees';

    You can see details of GRANT syntax from MySQL manual
    Grant permissions

  11. Now you’re ready to create connection from NetBeans, see Part 2: Create a connection.

References

Series NavigationAccessing MariaDB on NetBeans 8.2 using JDBC, Part 2: Create a connection >>

Leave a Reply