1. Navigate to the directory $WILDFLYHOME/modules/system/layers/base/com
  2. Create mysql/main directory
  3. Navigate to main directory and save MySQL JDBC driver's jar there
  4. Create a module.xml file with the content below:
<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-[VERSION]-bin.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>
  1. Access directory $WILDFLY_HOME/standalone/configuration and open the file standalone.xml
  2. Seek for datasource tag. There, you'll find a preconfigured datasource for H2 database, you can replace this configuratio with the code below or just increment your standalone.xml adding one more configuration:
    <!-- I have a project called social_network, it explains the names below -->
<datasource jta="true" jndi-name="java:jboss/datasources/social_network-ds" pool-name="social_network" enabled="true" use-java-context="true" use-ccm="true">
    <connection-url>jdbc:mysql://localhost:3306/social_network</connection-url>
    <driver>mysql</driver>
    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
    <pool>
        <min-pool-size>10</min-pool-size>
        <max-pool-size>100</max-pool-size>
        <prefill>true</prefill>
    </pool>
    <security>
        <user-name>root</user-name>
        <password>root</password>
    </security>
    <statement>
        <prepared-statement-cache-size>32</prepared-statement-cache-size>
        <share-prepared-statements>true</share-prepared-statements>
    </statement>
</datasource>
  1. Below your datasource you must a tag drivers, inside this tag, paste the code:
<driver name="mysql" module="com.mysql">
    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
  1. You must edit your project's persistence.xml too:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
 
    <persistence-unit name="livraria" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
 
        <!-- Dont forget to inform to your persistence.xml the datasource name -->
        <jta-data-source>java:jboss/datasources/social_network-ds</jta-data-source>
        <!-- Note: If you need to run a main class to popolate your database, remove the tag above -->
 
        <class>com.lucas.social_network.model.User</class>
 
        <!-- Once your are using a datasource, is not required to configure properties below -->
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/social_network" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />
 
            <property name="javax.persistence.validation.mode" value="none" />
 
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        </properties>
    </persistence-unit>
</persistence>

Voilá! :)