Hiển thị các bài đăng có nhãn database. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn database. Hiển thị tất cả bài đăng

Install and Configure MariaDB on Ubuntu

I. Installation

In your terminal execute the following commands:

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main'
sudo apt update
sudo apt -y install mariadb-server mariadb-client

You should be prompted to set your password.

Try myql -u root -p, if it does not work we need to configure the root user.

II. Configuration
Go back to your terminal and execute the following commands:

sudo mysql -u root
SELECT User,Host FROM mysql.user; # notice that root is assigned to localhost not %
DROP USER 'root'@'localhost';
CREATE USER 'root'@'%' IDENTIFIED BY 'secret';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Exit mysql and connect without using sudo.

In case something goes wrong. Here's how you can uninstall MariaDB

apt-get remove --purge mariadb-server mariadb-client 
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mariadb-server mariadb-client
sudo apt-get --purge remove "mysql*"
sudo rm -rf /etc/mysql

Open /etc/apt/sources.list and remove all instances of MariaDB.

Then finally run sudo apt update.

Hibernate OGM for MongoDB

So lately I've been playing with Hibernate OGM MongoDB's latest version 5.4.0.Beta2 but I'm not able to run a demo project created from wildfly-javaee7-war archetype following the documentation.

Here are the changes I've made to make it run the Arquillian test:


public static Archive<?> createTestArchive() {
String manifest = Descriptors.create(ManifestDescriptor.class).attribute("Dependencies", "org.hibernate.ogm:5.4 services, org.hibernate.ogm.mongodb:5.4 services")
.exportAsString();

return ShrinkWrap.create(WebArchive.class, "test.war") //
.addClasses(Member.class, MemberRegistration.class, Resources.class) //
.addAsResource(new StringAsset(manifest), "META-INF/MANIFEST.MF") //
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml") //
// doesn't work on this version
// .addAsResource("jboss-deployment-structure.xml", "WEB-INF/jboss-deployment-structure.xml") //
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") //
// Deploy our test datasource
.addAsWebInfResource("test-ds.xml");
}

Notice that instead of using jboss-deployment-structure file, we use a manifest. Maybe it's a bug in the release.

You can download the complete source code from:

  • https://github.com/czetsuya/Hibernate-OGM-MongoDB-Demo

How to use mariadb and liquibase together with maven on jboss

First you must define the needed dependency in your pom file.
<profile>
<id>mariadb</id>
<activation>
<property>
<name>env</name>
<value>mariadb</value>
</property>
</activation>
<properties>
<db.driver>org.mariadb.jdbc.Driver</db.driver>
<db.url>jdbc:mariadb://localhost:3306/mariadb</db.url>
<db.username>mariadb</db.username>
<db.password>mariadb</db.password>
</properties>
<dependencies>
<!-- Dependency for liquibase plugin -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.5.4</version>
</dependency>
</dependencies>
</profile>
Then we need to configure jboss datasource
<datasource jta="true"
jndi-name="java:jboss/datasources/MariaDBAdminDatasource" pool-name="MariaDBMariadb"
enabled="true" use-java-context="true" use-ccm="false">
<connection-url>jdbc:mariadb://127.0.0.1:3306/MariaDB</connection-url>
<driver-class>org.mariadb.jdbc.Driver</driver-class>
<driver>mariadb-driver</driver>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>MariaDB</user-name>
<password>MariaDB</password>
</security>
<validation>
<validate-on-match>true</validate-on-match>
<background-validation>true</background-validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
</validation>
<statement>
<prepared-statement-cache-size>10</prepared-statement-cache-size>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>

<drivers>
<driver name="mariadb-driver" module="org.mariadb">
<xa-datasource-class>org.mariadb.jdbc.MySQLDataSource</xa-datasource-class>
</driver>
</drivers>
And finally inside jboss modules folder we need to create a new folder: org\mariadb\main with mariadb-java-client-1.5.4.jar and module.xml. Content of module.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.mariadb">
<resources>
<resource-root path="mariadb-java-client-1.5.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

How to restore an oracle dump using imp command

The following steps will guide us in the restoration of an oracle dump file.
  1. connect as system and enter your password
  2. sqplus system@xe
  3. create user
  4. create user TEST_USER identified by password;
  5. grant roles
  6. grant CREATE SESSION, ALTER SESSION, CREATE DATABASE LINK, -
    CREATE MATERIALIZED VIEW, CREATE PROCEDURE, CREATE PUBLIC SYNONYM, -
    CREATE ROLE, CREATE SEQUENCE, CREATE SYNONYM, CREATE TABLE, -
    CREATE TRIGGER, CREATE TYPE, CREATE VIEW, UNLIMITED TABLESPACE -
    to TEST_USER;
  7. create permanent table space
  8. CREATE TABLESPACE testuser DATAFILE 'testuser.dat' SIZE 20M AUTOEXTEND ON;
  9. import the dump file
  10. imp system/password@xe file=d:\testuser.dmp fromuser=TEST_USER touser=TEST_USER log=d:\test_user_import.log
The above steps is with the assumption that we've created an oracle database backup using exp tool.

How to import and export a database dump in oracle


The following instruction will help us in importing and exporting our oracle database.

  1. Create and restore dump file (http://www.database.fi/2011/05/using-expdp-and-impdp-export-and-import-in-10g-11g/)
    1. Create dump file
      1. sqlplus system/oracle
      2. SQL> create directory dmpdir AS 'c:\temp';
      3. select directory_name, directory_path from dba_directories;
      4. expdp system/password version=’10.2.0.1’ dumpfile=czetsuya.dmp directory=dmpdir schemas=czetsuya
    2. Restore a dump file
      1. For import we can use the DATA_PUMP_DIR setting:
        1. ORACLE_XE\app\oracle\admin\XE\dpdump
      2. Copy dump file to folder above
      3. impdp system/password dumpfile=czetsuya.dmp directory=DATA_PUMP_DIR full=y logfile=czetsuya.log