Super duper cool guide for installing MySQL (MariaDB actually) and JDBC on Ubuntu 20.04
-
Install mariadb server using:
sudo apt install mariadb-server
-
Install the Java library for MariaDB using:
sudo apt install libmariadb-java
-
Start the mariadb service using:
sudo /etc/init.d/mysql start
-
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
-
Download this: https://dlm.mariadb.com/1785291/connectors/java/connector-java-2.7.4/mariadb-java-client-2.7.4.jar
-
Note down the full path to this jar. You will need it (best to move it to some known location)
-
Login to MariaDb, create a database, create one table under the database and add one row to the table.
-
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:
-
Compile with
javac <filename>.java
-
Run using
java -cp .:<path to the jar file which you noted in step 6> <classname>
All the best!