Mariadb java操作(一) 安装
【摘要】 下载依赖包yum install -y mariadb-server db初始化mysql_install_db --gssapi=OFF --user=root 命令拉起 初始化SQLCREATE DATABASE IF NOT EXISTS ttbb DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_bin;CREATE USER IF NOT EXIST...
下载依赖包
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
代码连接
代码,参考地址 https://github.com/Shoothzj/java-demo
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 !
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)