Skip to content

Commit 20bef56

Browse files
find plugin directory
1 parent dc838db commit 20bef56

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/libraries/Executor.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,31 @@ class Executor {
7474
if (lt(this.version, '8.0.11') && gte(this.version, '5.7.19')) {
7575
const initSocket = os.platform() === 'win32' ? `MySQL-${randomUUID()}` : `${dbPath}/i.sock`
7676
const initFileLocation = `${dbPath}/installX.sql`
77+
const pluginExtension = os.platform() === 'win32' ? 'dll' : 'so';
7778
//<8.0.11 does not have MySQL X turned on by default so we will be installing the X Plugin in this if statement.
7879
//MySQL 5.7.12 introduced the X plugin, but according to https://dev.mysql.com/doc/refman/5.7/en/document-store-setting-up.html, the database needs to be initialised with version 5.7.19.
7980
//If the MySQL version is >=5.7.19 & <8.0.11 then install the X Plugin
80-
const initFileText = `INSTALL PLUGIN mysqlx SONAME 'mysqlx.${os.platform() === 'win32' ? 'dll' : 'so'}';`
81+
const initFileText = `INSTALL PLUGIN mysqlx SONAME 'mysqlx.${pluginExtension}';`
8182
try {
8283
await fsPromises.writeFile(initFileLocation, initFileText, {encoding: 'utf8'})
8384
} catch (e) {
8485
this.logger.error('An error occurred while writing the init file to install MySQL X. The error was:', e)
8586
throw e
8687
}
8788

88-
const executed = await this.#executeFile(binaryFilepath, ['--no-defaults', '--skip-networking', `--init-file=${initFileLocation}`, `--socket=${initSocket}`, `--datadir=${datadir}`])
89+
let pluginPath: string;
90+
const firstPath = resolvePath(`${binaryFilepath}/../../lib/plugin`)
91+
const secondPath = '/usr/lib/mysql/plugin'
92+
93+
if (fs.existsSync(`${firstPath}/mysqlx.${pluginExtension}`)) {
94+
pluginPath = firstPath
95+
} else if (os.platform() === 'linux' && fs.existsSync(`${secondPath}/mysqlx.so`)) {
96+
pluginPath = secondPath
97+
} else {
98+
throw 'Could not install MySQL X as the path to the plugin cannot be found.'
99+
}
100+
101+
const executed = await this.#executeFile(binaryFilepath, ['--no-defaults', '--skip-networking', `--init-file=${initFileLocation}`, `--socket=${initSocket}`, `--datadir=${datadir}`, `--plugin-dir=${pluginPath}`])
89102
this.logger.log('Executed:', executed)
90103
}
91104

0 commit comments

Comments
 (0)