Skip to content

Commit 8150c1b

Browse files
Add support for MySQL >=5.7.19 (#181)
* add install plugin to init-file * add init file install execution * add datadir * find plugin directory * use plugin-load-add * fix typo * remove quotation marks * add mysqlx socket option * remove need for seperate MySQL startup for x init * remove commented out code * change message to check for * test 5.7.12 * finalize changes * remove ignoreUnsupportedSystemVersion in tests * add windows 2019 stress test
1 parent 7a1e18e commit 8150c1b

File tree

7 files changed

+47
-14
lines changed

7 files changed

+47
-14
lines changed

.github/workflows/stress.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: [macos-latest, ubuntu-latest, windows-latest]
16+
os: [macos-latest, ubuntu-latest, windows-2019, windows-2022]
1717

1818
steps:
1919
- name: Free Disk Space (Ubuntu)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Requirements for Linux:
2727

2828
#### Currently supported MySQL versions
2929

30-
- If using the system installed MySQL server: 8.0.11 and newer
30+
- If using the system installed MySQL server: 5.7.19 and newer
3131
- If not using the system installed MySQL server: 8.0.39 - 8.0.41, 8.1.0 - 8.3.0, 8.4.2 - 8.4.4, and 9.0.1 - 9.2.0
3232

3333
## Example Usage - Application Code
@@ -112,11 +112,11 @@ Default: undefined
112112
Description: Version of MySQL to use for the database. Uses semver for getting the version, so valid semver versions are allowed. For example, `8.x` is a valid version and will use the latest 8.x MySQL version.
113113

114114
If left undefined:
115-
- If the system has MySQL installed, the system-installed version will be used. If the installed version is not supported by this package (currently <8.0.11), an error will be thrown unless `ignoreUnsupportedSystemVersion` is set to `true`.
115+
- If the system has MySQL installed, the system-installed version will be used. If the installed version is not supported by this package (currently <5.7.19), an error will be thrown unless `ignoreUnsupportedSystemVersion` is set to `true`.
116116
- If the system does not have MySQL installed, the latest version of MySQL in the `versions.json` file in this package will be downloaded.
117117

118118
If defined:
119-
- If the version is older than 8.0.11, an error will be thrown as this package does not currently support those versions of MySQL.
119+
- If the version is older than 5.7.19, an error will be thrown as this package does not currently support those versions of MySQL.
120120
- If the desired version of MySQL is installed on the system, the installed version will be used. Otherwise the selected version will be downloaded from the MySQL CDN as long as it can be found in the `versions.json` file. If it cannot be found in that file, an error will be thrown.
121121

122122
- `dbName: string`
@@ -179,7 +179,7 @@ Description: The port that the MySQL X Plugin will listen on. If set to 0, a ran
179179

180180
Default: false
181181

182-
Description: This option only applies if the system-installed MySQL version is lower than the oldest supported MySQL version for this package (8.0.11) and the `version` option is not defined. If set to `true`, this package will use the latest version of MySQL instead of the system-installed version. If `false`, the package will throw an error.
182+
Description: This option only applies if the system-installed MySQL version is lower than the oldest supported MySQL version for this package (5.7.19) and the `version` option is not defined. If set to `true`, this package will use the latest version of MySQL instead of the system-installed version. If `false`, the package will throw an error.
183183

184184
- `downloadRetries: number`
185185

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {normalize as normalizePath} from 'path'
44
import { tmpdir } from "os";
55
import { valid as validSemver, coerce as coerceSemver } from "semver";
66

7-
export const MIN_SUPPORTED_MYSQL = '8.0.11';
7+
export const MIN_SUPPORTED_MYSQL = '5.7.19';
88

99
export const DEFAULT_OPTIONS_GENERATOR: () => InternalServerOptions = () => ({
1010
version: undefined,

src/libraries/Executor.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChildProcess, execFile, spawn } from "child_process"
2-
import {coerce, satisfies} from 'semver';
2+
import {coerce, gte, lt, satisfies} from 'semver';
33
import * as os from 'os'
44
import * as fsPromises from 'fs/promises';
55
import * as fs from 'fs';
@@ -71,7 +71,43 @@ class Executor {
7171
const socket = os.platform() === 'win32' ? `MySQL-${randomUUID()}` : `${dbPath}/m.sock`
7272
const xSocket = os.platform() === 'win32' ? `MySQLX-${randomUUID()}` : `${dbPath}/x.sock`
7373

74-
const process = spawn(binaryFilepath, ['--no-defaults', `--port=${port}`, `--datadir=${datadir}`, `--mysqlx-port=${mySQLXPort}`, `--mysqlx-socket=${xSocket}`, `--socket=${socket}`, `--general-log-file=${logFile}`, '--general-log=1', `--init-file=${dbPath}/init.sql`, '--bind-address=127.0.0.1', '--innodb-doublewrite=OFF', '--mysqlx=FORCE', `--log-error=${errorLogFile}`, `--user=${os.userInfo().username}`], {signal: this.DBDestroySignal.signal, killSignal: 'SIGKILL'})
74+
const mysqlArguments = [
75+
'--no-defaults',
76+
`--port=${port}`,
77+
`--datadir=${datadir}`,
78+
`--mysqlx-port=${mySQLXPort}`,
79+
`--mysqlx-socket=${xSocket}`,
80+
`--socket=${socket}`,
81+
`--general-log-file=${logFile}`,
82+
'--general-log=1',
83+
`--init-file=${dbPath}/init.sql`,
84+
'--bind-address=127.0.0.1',
85+
'--innodb-doublewrite=OFF',
86+
'--mysqlx=FORCE',
87+
`--log-error=${errorLogFile}`,
88+
`--user=${os.userInfo().username}`
89+
]
90+
91+
//<8.0.11 does not have MySQL X turned on by default so we will be installing the X Plugin in this if statement.
92+
//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.
93+
//If the MySQL version is >=5.7.19 & <8.0.11 then install the X Plugin
94+
if (lt(this.version, '8.0.11') && gte(this.version, '5.7.19')) {
95+
const pluginExtension = os.platform() === 'win32' ? 'dll' : 'so';
96+
let pluginPath: string;
97+
const firstPath = resolvePath(`${binaryFilepath}/../../lib/plugin`)
98+
const secondPath = '/usr/lib/mysql/plugin'
99+
100+
if (fs.existsSync(`${firstPath}/mysqlx.${pluginExtension}`)) {
101+
pluginPath = firstPath
102+
} else if (os.platform() === 'linux' && fs.existsSync(`${secondPath}/mysqlx.so`)) {
103+
pluginPath = secondPath
104+
} else {
105+
throw 'Could not install MySQL X as the path to the plugin cannot be found.'
106+
}
107+
mysqlArguments.splice(1, 0, `--plugin-dir=${pluginPath}`, `--plugin-load-add=mysqlx=mysqlx.${pluginExtension}`)
108+
}
109+
110+
const process = spawn(binaryFilepath, mysqlArguments, {signal: this.DBDestroySignal.signal, killSignal: 'SIGKILL'})
75111

76112
//resolveFunction is the function that will be called to resolve the promise that stops the database.
77113
//If resolveFunction is not undefined, the database has received a kill signal and data cleanup procedures should run.
@@ -160,7 +196,7 @@ class Executor {
160196
if (!killed) {
161197
reject('Failed to kill MySQL process to retry listening on a free port.')
162198
}
163-
} else if (file.includes('ready for connections. Version:')) {
199+
} else if (file.includes('ready for connections. Version:') || file.includes('Server starts handling incoming connections')) {
164200
fs.unwatchFile(errorLogFile)
165201
resolve({
166202
port,

stress-tests/stress.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ for (let i = 0; i < 100; i++) {
1818

1919
const options: ServerOptions = {
2020
username: 'dbuser',
21-
logLevel: 'LOG',
22-
ignoreUnsupportedSystemVersion: true
21+
logLevel: 'LOG'
2322
}
2423

2524
if (process.env.useCIDBPath) {

tests/sql.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ beforeEach(async () => {
1818

1919
const options: ServerOptions = {
2020
username: 'root',
21-
logLevel: 'LOG',
22-
ignoreUnsupportedSystemVersion: true
21+
logLevel: 'LOG'
2322
}
2423

2524
if (process.env.useCIDBPath) {

tests/versions.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ for (const version of versions) {
2525
dbName: 'testingdata',
2626
username: username,
2727
logLevel: 'LOG',
28-
ignoreUnsupportedSystemVersion: true,
2928
initSQLString: 'CREATE DATABASE mytestdb;'
3029
}
3130

0 commit comments

Comments
 (0)