Skip to content

Instantly share code, notes, and snippets.

@abaksy
Last active April 5, 2025 01:25
Show Gist options
  • Save abaksy/229cdc29f7bc7b8043aa9cde2f34afa0 to your computer and use it in GitHub Desktop.
Save abaksy/229cdc29f7bc7b8043aa9cde2f34afa0 to your computer and use it in GitHub Desktop.
mysql-jdbc-ubuntu-install

Super duper cool guide for installing MySQL (MariaDB actually) and JDBC on Ubuntu 20.04

  1. Install mariadb server using: sudo apt install mariadb-server

  2. Install the Java library for MariaDB using: sudo apt install libmariadb-java

  3. Start the mariadb service using: sudo /etc/init.d/mysql start

  4. Now you will login to the mariaDB and create a new user that does not need root a) Connect to MY-SQL using: sudo mysql -u root

    b) Delete the current Root User from the User Table: DROP USER 'root'@'localhost';

    c) Create a new ROOT user (You can create a different user if needed): CREATE USER 'root'@'%' IDENTIFIED BY 'password_here';

    d) Grant permissions to new User (ROOT): GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

    e) Flush privileges, so that the Grant tables get reloaded immediately: FLUSH PRIVILEGES;

    f) Now it's all good. Just in case, check whether a new root user is created: SELECT User,Host FROM mysql.user;

    g) exit from mariadb using 'exit' and then try logging in again using the command mariadb -u root -p

  5. Download this: https://dlm.mariadb.com/1785291/connectors/java/connector-java-2.7.4/mariadb-java-client-2.7.4.jar

  6. Note down the full path to this jar. You will need it (best to move it to some known location)

  7. Login to MariaDb, create a database, create one table under the database and add one row to the table.

  8. create some JDBC program. The class name is "org.mariadb.jdbc.Driver" (use this with Class.forName) Username is 'root', password is whatever you gave in step 4c. Database URL is of the form:

  9. Compile with javac <filename>.java

  10. Run using java -cp .:<path to the jar file which you noted in step 6> <classname> All the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment