本文整理汇总了Java中com.mysql.management.MysqldResource类的典型用法代码示例。如果您正苦于以下问题:Java MysqldResource类的具体用法?Java MysqldResource怎么用?Java MysqldResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MysqldResource类属于com.mysql.management包,在下文中一共展示了MysqldResource类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.mysql.management.MysqldResource; //导入依赖的package包/类
@Override
public String start() {
Map<String,String> args = new HashMap<>();
args.put(MysqldResourceI.PORT, Integer.toString(DB_PORT));
args.put(MysqldResourceI.INITIALIZE_USER, "true");
args.put(MysqldResourceI.INITIALIZE_USER_NAME, DB_USER);
args.put(MysqldResourceI.INITIALIZE_PASSWORD, DB_PASS);
engine = new MysqldResource(new File(DB_PATH));
engine.start("jdbdt-mysqld-thread", args);
if (!engine.isRunning()) {
throw new RuntimeException("MySQL did not start.");
}
return String.format
(
"jdbc:mysql://127.0.0.1:%d/jdbdt?user=%s&password=%s&createDatabaseIfNotExist=true",
DB_PORT,
DB_USER,
DB_PASS
);
}
示例2: setUp
import com.mysql.management.MysqldResource; //导入依赖的package包/类
public void setUp() {
File databaseDir = new File(new File(baseDatabaseDir), databaseName);
PrintStream nps = this.getNullAppender();
mysqldResource = new MysqldResource(databaseDir, null, null, nps, nps);
Map<String, String> database_options = new HashMap<String, String>();
database_options.put(MysqldResourceI.PORT, Integer.toString(port));
database_options.put(MysqldResourceI.INITIALIZE_USER, "true");
database_options.put(MysqldResourceI.INITIALIZE_USER_NAME, username);
database_options.put(MysqldResourceI.INITIALIZE_PASSWORD, password);
mysqldResource.start("embedded-mysqld-thread-" + System.currentTimeMillis(), database_options);
if (!mysqldResource.isRunning()) {
throw new RuntimeException("MySQL did not start.");
}
}
示例3: EmbeddedMySQL
import com.mysql.management.MysqldResource; //导入依赖的package包/类
private EmbeddedMySQL() throws InterruptedException
{
port = AvailablePortFinder.getNextAvailable(internalCounter.getAndIncrement());
dataDir = Files.createTempDir();
mysqld = new MysqldResource(dataDir);
Map<String, String> props = ImmutableMap.of(MysqldResourceI.PORT, Integer.toString(port),
MysqldResourceI.INITIALIZE_USER, "true",
MysqldResourceI.INITIALIZE_USER_NAME, "user",
MysqldResourceI.INITIALIZE_PASSWORD, "pass",
"default-time-zone", "+00:00");
mysqld.start("mysql-daemon", props);
if (!mysqld.isRunning()) {
throw new IllegalStateException("MySQL failed to start");
}
while (!mysqld.isReadyForConnections()) { Thread.sleep(100); }
}
示例4: startDb
import com.mysql.management.MysqldResource; //导入依赖的package包/类
/**
* Start the database.
*/
public void startDb() {
Map<String, String> databaseOptions = new HashMap<>();
databaseOptions.put(MysqldResourceI.PORT, Integer.toString(port));
mysqldResource = new MysqldResource(new File(databaseDir, databaseName));
mysqldResource.start("embedded-mysqld-db-thread-" + System.currentTimeMillis(),
databaseOptions);
if (!mysqldResource.isRunning()) {
throw new RuntimeException("Failed to start embedded MySQL DB!");
}
LOG.debug("MySQL started successfully");
}
示例5: internalStop
import com.mysql.management.MysqldResource; //导入依赖的package包/类
void internalStop() {
try {
MysqldResource mysqldResource = new MysqldResource(DATABASE_DIR);
mysqldResource.shutdown();
if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
Runtime.getRuntime().exec("taskkill /F /PID " + EmbeddedMysqlProvider.this.mysqlpid);
} else {
Runtime.getRuntime().exec("kill -9 " + EmbeddedMysqlProvider.this.mysqlpid);
}
FileUtils.deleteDirectory(DATABASE_DIR);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: start
import com.mysql.management.MysqldResource; //导入依赖的package包/类
public void start(String databaseName) {
String tmpDir = System.getProperty("java.io.tmpdir");
File baseDir = new File(tmpDir, databaseName);
FileUtils.deleteQuietly(baseDir);
int port = getFreePort();
Map<String, String> databaseOptions = new HashMap<>();
databaseOptions.put(MysqldResourceI.PORT, Integer.toString(port));
mysqldResource = new MysqldResource(baseDir);
mysqldResource.start("mysql", databaseOptions);
url = "jdbc:mysql://localhost:" + port + "/" + databaseName + "?" + "createDatabaseIfNotExist=true";
}