下载依赖包
yum install -y mariadb-server
db初始化
mysql_install_db --gssapi=OFF --user=root
命令拉起
初始化SQL
CREATE DATABASE IF NOT EXISTS ttbb DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER IF NOT EXISTS hzj identified by 'Mysql@123';
GRANT ALL ON ttbb .* to hzj@'%';
/usr/bin/mysqld_safe --datadir='/var/lib/mysql' --user=root --init-file=/opt/sh/init.sql
代码连接
package com.github.shoothzj.demo.db.jdbc.mariadb;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
/**
* @author akka
*/
public class MariaDBBegin {
// The JDBC Connector Class.
private static final String DRIVER_NAME = "org.mariadb.jdbc.Driver";
private static final String CONNECTION = "jdbc:mariadb://localhost:3306/" + TestConstant.TABLE_NAME;
public static void main(String[] args) throws ClassNotFoundException, SQLException {
System.out.println(DRIVER_NAME);
Class.forName(DRIVER_NAME);
// Properties for user and password.
Properties p = new Properties();
p.put("user", TestConstant.USER_NAME);
p.put("password", TestConstant.PASSWORD);
// Now try to connect
Connection c = DriverManager.getConnection(CONNECTION, p);
System.out.println("It works !");
c.close();
}
}
输出
org.mariadb.jdbc.Driver
It works !
网友评论