Posted
over 3 years
ago
by
Frederic Descamps
This post is the second post of a series of articles on extending MySQL with the Component Infrastructure:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using the Component Infrastructure – part 2: building the
... [More]
serverExtending MySQL using the Component Infrastructure – part 3: component servicesIt’s time to start coding our new component \o/
In the MySQL Server’s source directory (see part 2), we will create a new directory for our component:
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ cd ..
[fred@imac ~workspace/mysql-server]$ mkdir components/viruscan
[fred@imac ~workspace/mysql-server]$ cd components/viruscan
We will create 3 files:
CMakeLists.txtscan.hscan.ccOur component will of course use some services from the Component Infrastructure.
All services are listed in the documentation page Component Services Inventory.
We also need others components like the log
The required header for the services we need are:
component_implementation (this is for the macros that every component implementation must include)log_builtins (to log messages in error log and performance_schema.error_log table)mysql_current_thread_reader (to get some user context)dynamic_privileges and security_contextudf_registration (to create the UDFs)status_variable_registration (to create the new status variables)First Step in extending MySQL’s world
We will now create a component that we can load. It won’t do anything yet, just have the possibility to be installed and removed.
We start with scan.h that will be minimal:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define LOG_COMPONENT_TAG "viruscan"
#include
view raw
scan.h
hosted with ❤ by GitHub
As you can see, nothing special, the Copyright header and then we define a tag for our component LOG_COMPONENT_TAG.
And finally we include the header for the component implementation.
Then we create our component code (which is still minimal for the moment), scan.cc:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define LOG_COMPONENT_TAG "viruscan"
#define NO_SIGNATURE_CHANGE 0
#define SIGNATURE_CHANGE 1
#include
static mysql_service_status_t viruscan_service_init() {
mysql_service_status_t result = 0;
return result;
}
static mysql_service_status_t viruscan_service_deinit() {
mysql_service_status_t result = 0;
return result;
}
BEGIN_COMPONENT_PROVIDES(viruscan_service)
END_COMPONENT_PROVIDES();
BEGIN_COMPONENT_REQUIRES(viruscan_service)
END_COMPONENT_REQUIRES();
/* A list of metadata to describe the Component. */
BEGIN_COMPONENT_METADATA(viruscan_service)
METADATA("mysql.author", "Oracle Corporation"),
METADATA("mysql.license", "GPL"), METADATA("mysql.dev", "lefred"),
END_COMPONENT_METADATA();
/* Declaration of the Component. */
DECLARE_COMPONENT(viruscan_service,
"mysql:viruscan_service")
viruscan_service_init,
viruscan_service_deinit END_DECLARE_COMPONENT();
/* Defines list of Components contained in this library. Note that for now
we assume that library will have exactly one Component. */
DECLARE_LIBRARY_COMPONENTS &COMPONENT_REF(viruscan_service)
END_DECLARE_LIBRARY_COMPONENTS
view raw
scan.cc
hosted with ❤ by GitHub
We include our previously created header (scan.h) ant then we create two functions that are called when installing and uninstalling the component.
If the component provides services or requires services we also need to add them in the following sections. Currently those are empty, we will use them later
After, we also add some metadata for the component.
And we finish with the declaration of the component, referencing the previously created function to called at install (init) and uninstall (deinit).
The library could contain multiple components, ours contains only one.
Building our component
Before building our component we still need one file CMakeLists.txt with the following content:
DISABLE_MISSING_PROFILE_WARNING()
MYSQL_ADD_COMPONENT(viruscan
scan.cc
MODULE_ONLY
TEST_ONLY
)
For the moment we are not interested in profiling our test component. Once we will require to link the component with ClamAV, we will also update this file.
Now we can run cmake again (same command as in part 2):
[fred@imac ~workspace/mysql-server]$ cd BIN-DEBUG
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ cmake .. -DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../downloads
Now we can build our component only:
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ make component_viruscan
Perfect !
Testing our component
We can now test our component, we use again mtr to run MySQL:
$ cd mysql-test
$ perl mtr --mem --start
On another terminal (I usually keep it dedicated for testing with MySQL Shell), we can try to install and uninstall our freshly build component:
Excellent !
Conclusion
We already created our first component, the first step in extending MySQL Server, congratulations !
In the next articles, we will of course extend the capabilities of our component to make it useful.
The next step will be about using the component logging service to log messages in error log.
Stay tuned and as usual, enjoy and extend MySQL with code ! [Less]
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the third post of a series of articles on extending MySQL with the Component Infrastructure:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using the Component Infrastructure – part 2: building the
... [More]
serverExtending MySQL using the Component Infrastructure – part 3: component servicesExtending MySQL using the Component Infrastructure – part 4: error loggingExtending MySQL using the Component Infrastructure – part 5: privilegesExtending MySQL using the Component Infrastructure – part 6: functionsIt’s time to start coding our new component \o/
In the MySQL Server’s source directory (see part 2), we will create a new directory for our component:
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ cd ..
[fred@imac ~workspace/mysql-server]$ mkdir components/viruscan
[fred@imac ~workspace/mysql-server]$ cd components/viruscan
We will create 3 files:
CMakeLists.txtscan.hscan.ccOur component will of course use some services from the Component Infrastructure.
All services are listed in the documentation page Component Services Inventory.
We also need others components like the log
The required header for the services we need are:
component_implementation (this is for the macros that every component implementation must include)log_builtins (to log messages in error log and performance_schema.error_log table)mysql_current_thread_reader (to get some user context)dynamic_privileges and security_contextudf_registration (to create the UDFs)status_variable_registration (to create the new status variables)First Step in extending MySQL’s world
We will now create a component that we can load. It won’t do anything yet, just have the possibility to be installed and removed.
We start with scan.h that will be minimal:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define LOG_COMPONENT_TAG "viruscan"
#include
view raw
scan.h
hosted with ❤ by GitHub
As you can see, nothing special, the Copyright header and then we define a tag for our component LOG_COMPONENT_TAG.
And finally we include the header for the component implementation.
Then we create our component code (which is still minimal for the moment), scan.cc:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define LOG_COMPONENT_TAG "viruscan"
#define NO_SIGNATURE_CHANGE 0
#define SIGNATURE_CHANGE 1
#include
static mysql_service_status_t viruscan_service_init() {
mysql_service_status_t result = 0;
return result;
}
static mysql_service_status_t viruscan_service_deinit() {
mysql_service_status_t result = 0;
return result;
}
BEGIN_COMPONENT_PROVIDES(viruscan_service)
END_COMPONENT_PROVIDES();
BEGIN_COMPONENT_REQUIRES(viruscan_service)
END_COMPONENT_REQUIRES();
/* A list of metadata to describe the Component. */
BEGIN_COMPONENT_METADATA(viruscan_service)
METADATA("mysql.author", "Oracle Corporation"),
METADATA("mysql.license", "GPL"), METADATA("mysql.dev", "lefred"),
END_COMPONENT_METADATA();
/* Declaration of the Component. */
DECLARE_COMPONENT(viruscan_service,
"mysql:viruscan_service")
viruscan_service_init,
viruscan_service_deinit END_DECLARE_COMPONENT();
/* Defines list of Components contained in this library. Note that for now
we assume that library will have exactly one Component. */
DECLARE_LIBRARY_COMPONENTS &COMPONENT_REF(viruscan_service)
END_DECLARE_LIBRARY_COMPONENTS
view raw
scan.cc
hosted with ❤ by GitHub
We include our previously created header (scan.h) ant then we create two functions that are called when installing and uninstalling the component.
If the component provides services or requires services we also need to add them in the following sections. Currently those are empty, we will use them later
After, we also add some metadata for the component.
And we finish with the declaration of the component, referencing the previously created function to called at install (init) and uninstall (deinit).
The library could contain multiple components, ours contains only one.
Building our component
Before building our component we still need one file CMakeLists.txt with the following content:
DISABLE_MISSING_PROFILE_WARNING()
MYSQL_ADD_COMPONENT(viruscan
scan.cc
MODULE_ONLY
TEST_ONLY
)
For the moment we are not interested in profiling our test component. Once we will require to link the component with ClamAV, we will also update this file.
Now we can run cmake again (same command as in part 2):
[fred@imac ~workspace/mysql-server]$ cd BIN-DEBUG
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ cmake .. -DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../downloads
Now we can build our component only:
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ make component_viruscan
Perfect !
Testing our component
We can now test our component, we use again mtr to run MySQL:
$ cd mysql-test
$ perl mtr --mem --start
On another terminal (I usually keep it dedicated for testing with MySQL Shell), we can try to install and uninstall our freshly build component:
Excellent !
Conclusion
We already created our first component, the first step in extending MySQL Server, congratulations !
In the next articles, we will of course extend the capabilities of our component to make it useful.
The next step will be about using the component logging service to log messages in error log.
Stay tuned and as usual, enjoy and extend MySQL with code ! [Less]
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the third post of a series of articles on extending MySQL with the Component Infrastructure:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using the Component Infrastructure – part 2: building the
... [More]
serverExtending MySQL using the Component Infrastructure – part 3: component servicesExtending MySQL using the Component Infrastructure – part 4: error loggingExtending MySQL using the Component Infrastructure – part 5: privilegesIt’s time to start coding our new component \o/
In the MySQL Server’s source directory (see part 2), we will create a new directory for our component:
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ cd ..
[fred@imac ~workspace/mysql-server]$ mkdir components/viruscan
[fred@imac ~workspace/mysql-server]$ cd components/viruscan
We will create 3 files:
CMakeLists.txtscan.hscan.ccOur component will of course use some services from the Component Infrastructure.
All services are listed in the documentation page Component Services Inventory.
We also need others components like the log
The required header for the services we need are:
component_implementation (this is for the macros that every component implementation must include)log_builtins (to log messages in error log and performance_schema.error_log table)mysql_current_thread_reader (to get some user context)dynamic_privileges and security_contextudf_registration (to create the UDFs)status_variable_registration (to create the new status variables)First Step in extending MySQL’s world
We will now create a component that we can load. It won’t do anything yet, just have the possibility to be installed and removed.
We start with scan.h that will be minimal:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define LOG_COMPONENT_TAG "viruscan"
#include
view raw
scan.h
hosted with ❤ by GitHub
As you can see, nothing special, the Copyright header and then we define a tag for our component LOG_COMPONENT_TAG.
And finally we include the header for the component implementation.
Then we create our component code (which is still minimal for the moment), scan.cc:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#define LOG_COMPONENT_TAG "viruscan"
#define NO_SIGNATURE_CHANGE 0
#define SIGNATURE_CHANGE 1
#include
static mysql_service_status_t viruscan_service_init() {
mysql_service_status_t result = 0;
return result;
}
static mysql_service_status_t viruscan_service_deinit() {
mysql_service_status_t result = 0;
return result;
}
BEGIN_COMPONENT_PROVIDES(viruscan_service)
END_COMPONENT_PROVIDES();
BEGIN_COMPONENT_REQUIRES(viruscan_service)
END_COMPONENT_REQUIRES();
/* A list of metadata to describe the Component. */
BEGIN_COMPONENT_METADATA(viruscan_service)
METADATA("mysql.author", "Oracle Corporation"),
METADATA("mysql.license", "GPL"), METADATA("mysql.dev", "lefred"),
END_COMPONENT_METADATA();
/* Declaration of the Component. */
DECLARE_COMPONENT(viruscan_service,
"mysql:viruscan_service")
viruscan_service_init,
viruscan_service_deinit END_DECLARE_COMPONENT();
/* Defines list of Components contained in this library. Note that for now
we assume that library will have exactly one Component. */
DECLARE_LIBRARY_COMPONENTS &COMPONENT_REF(viruscan_service)
END_DECLARE_LIBRARY_COMPONENTS
view raw
scan.cc
hosted with ❤ by GitHub
We include our previously created header (scan.h) ant then we create two functions that are called when installing and uninstalling the component.
If the component provides services or requires services we also need to add them in the following sections. Currently those are empty, we will use them later
After, we also add some metadata for the component.
And we finish with the declaration of the component, referencing the previously created function to called at install (init) and uninstall (deinit).
The library could contain multiple components, ours contains only one.
Building our component
Before building our component we still need one file CMakeLists.txt with the following content:
DISABLE_MISSING_PROFILE_WARNING()
MYSQL_ADD_COMPONENT(viruscan
scan.cc
MODULE_ONLY
TEST_ONLY
)
For the moment we are not interested in profiling our test component. Once we will require to link the component with ClamAV, we will also update this file.
Now we can run cmake again (same command as in part 2):
[fred@imac ~workspace/mysql-server]$ cd BIN-DEBUG
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ cmake .. -DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../downloads
Now we can build our component only:
[fred@imac ~workspace/mysql-server/BIN-DEBUG]$ make component_viruscan
Perfect !
Testing our component
We can now test our component, we use again mtr to run MySQL:
$ cd mysql-test
$ perl mtr --mem --start
On another terminal (I usually keep it dedicated for testing with MySQL Shell), we can try to install and uninstall our freshly build component:
Excellent !
Conclusion
We already created our first component, the first step in extending MySQL Server, congratulations !
In the next articles, we will of course extend the capabilities of our component to make it useful.
The next step will be about using the component logging service to log messages in error log.
Stay tuned and as usual, enjoy and extend MySQL with code ! [Less]
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the second post of a series of articles on extending MySQL with the Component Infrastructure:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using the Component Infrastructure – part 2: building the
... [More]
serverExtending MySQL using the Component Infrastructure – part 3: component servicesIn the first part of this series, we described the main idea of our new component.
Now we need to setup our development environment and compile the server from scratch.
Downloading the sources
As written in the first part, there are multiple ways to get the sources of MySQL and I use the repository on GitHub. You need then to have git installed:
$ git clone https://github.com/mysql/mysql-server.git
Then you need to prepare build directory:
$ cd mysql-server
$ mkdir BIN-DEBUG
Before being able to compile MySQL Server, you will also need to install some dependencies like CMake, a compiler, make and curses dev package on Linux, bison…
Building MySQL
$ cd BIN-DEBUG
$ cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../downloads
We specify the download of the required version of boost
$ make -j 4
-j 4 to use 4 compile threads, you might need to tune according your system.
When everything is compiled, you can run the new compiled server and test it.
Testing
The easiest way to test it, is to use mtr:
$ cd mysql-test
$ perl mtr --mem --start
...
worker[1] Using config include/default_my.cnf
worker[1] Port and socket path for server(s):
worker[1] mysqld.1 13000 /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
worker[1] Waiting for server(s) to exit...
We can use MySQL Shell and the socket file to connect to our freshly compiled MySQL Server:
$ mysqlsh --sql -u root \
-S /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
Conclusion
We are now able to compile MySQL from source and start our new built server. This will be the base for our new component.
In our next article we will setup check which component services we need and create the skeleton of our component. [Less]
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the second post of a series of articles on extending MySQL with the Component Infrastructure:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using the Component Infrastructure – part 2: building the serverIn
... [More]
the first part of this series, we described the main idea of our new component.
Now we need to setup our development environment and compile the server from scratch.
Downloading the sources
As written in the first part, there are multiple ways to get the sources of MySQL and I use the repository on GitHub. You need then to have git installed:
$ git clone https://github.com/mysql/mysql-server.git
Then you need to prepare build directory:
$ cd mysql-server
$ mkdir BIN-DEBUG
Before being able to compile MySQL Server, you will also need to install some dependencies like CMake, a compiler, make and curses dev package on Linux, bison…
Building MySQL
$ cd BIN-DEBUG
$ cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../downloads
We specify the download of the required version of boost
$ make -j 4
-j 4 to use 4 compile threads, you might need to tune according your system.
When everything is compiled, you can run the new compiled server and test it.
Testing
The easiest way to test it, is to use mtr:
$ cd mysql-test
$ perl mtr --mem --start
...
worker[1] Using config include/default_my.cnf
worker[1] Port and socket path for server(s):
worker[1] mysqld.1 13000 /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
worker[1] Waiting for server(s) to exit...
We can use MySQL Shell and the socket file to connect to our freshly compiled MySQL Server:
$ mysqlsh --sql -u root \
-S /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
Conclusion
We are now able to compile MySQL from source and start our new built server. This will be the base for our new component.
In our next article we will setup check which component services we need and create the skeleton of our component. [Less]
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the second post of a series of articles on extending MySQL with the Component Infrastructure:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using the Component Infrastructure – part 2: building the
... [More]
serverExtending MySQL using the Component Infrastructure – part 3: component servicesExtending MySQL using the Component Infrastructure – part 4: error loggingExtending MySQL using the Component Infrastructure – part 5: privilegesIn the first part of this series, we described the main idea of our new component.
Now we need to setup our development environment and compile the server from scratch.
Downloading the sources
As written in the first part, there are multiple ways to get the sources of MySQL and I use the repository on GitHub. You need then to have git installed:
$ git clone https://github.com/mysql/mysql-server.git
Then you need to prepare build directory:
$ cd mysql-server
$ mkdir BIN-DEBUG
Before being able to compile MySQL Server, you will also need to install some dependencies like CMake, a compiler, make and curses dev package on Linux, bison…
Building MySQL
$ cd BIN-DEBUG
$ cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../downloads
We specify the download of the required version of boost
$ make -j 4
-j 4 to use 4 compile threads, you might need to tune according your system.
When everything is compiled, you can run the new compiled server and test it.
Testing
The easiest way to test it, is to use mtr:
$ cd mysql-test
$ perl mtr --mem --start
...
worker[1] Using config include/default_my.cnf
worker[1] Port and socket path for server(s):
worker[1] mysqld.1 13000 /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
worker[1] Waiting for server(s) to exit...
We can use MySQL Shell and the socket file to connect to our freshly compiled MySQL Server:
$ mysqlsh --sql -u root \
-S /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
Conclusion
We are now able to compile MySQL from source and start our new built server. This will be the base for our new component.
In our next article we will setup check which component services we need and create the skeleton of our component. [Less]
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the second post of a series of articles on extending MySQL with the Component Infrastructure:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using the Component Infrastructure – part 2: building the
... [More]
serverExtending MySQL using the Component Infrastructure – part 3: component servicesExtending MySQL using the Component Infrastructure – part 4: error loggingExtending MySQL using the Component Infrastructure – part 5: privilegesExtending MySQL using the Component Infrastructure – part 6: functionsIn the first part of this series, we described the main idea of our new component.
Now we need to setup our development environment and compile the server from scratch.
Downloading the sources
As written in the first part, there are multiple ways to get the sources of MySQL and I use the repository on GitHub. You need then to have git installed:
$ git clone https://github.com/mysql/mysql-server.git
Then you need to prepare build directory:
$ cd mysql-server
$ mkdir BIN-DEBUG
Before being able to compile MySQL Server, you will also need to install some dependencies like CMake, a compiler, make and curses dev package on Linux, bison…
Building MySQL
$ cd BIN-DEBUG
$ cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../downloads
We specify the download of the required version of boost
$ make -j 4
-j 4 to use 4 compile threads, you might need to tune according your system.
When everything is compiled, you can run the new compiled server and test it.
Testing
The easiest way to test it, is to use mtr:
$ cd mysql-test
$ perl mtr --mem --start
...
worker[1] Using config include/default_my.cnf
worker[1] Port and socket path for server(s):
worker[1] mysqld.1 13000 /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
worker[1] Waiting for server(s) to exit...
We can use MySQL Shell and the socket file to connect to our freshly compiled MySQL Server:
$ mysqlsh --sql -u root \
-S /home/fred/workspace/mysql-server/BIN-DEBUG/mysql-test/var/tmp/mysqld.1.sock
Conclusion
We are now able to compile MySQL from source and start our new built server. This will be the base for our new component.
In our next article we will setup check which component services we need and create the skeleton of our component. [Less]
|
Posted
over 3 years
ago
by
Oracle MySQL Group
Includes the new product features and releases, top webinars, top blogs, top customer references, top videos, top white papers and more from 2021.
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the first post of a series of articles on extending MySQL with the Component Infrastructure, the list above will be updated as new articles are published:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using
... [More]
the Component Infrastructure – part 2: building the serverExtending MySQL using the Component Infrastructure – part 3: component servicesExtending MySQL using the Component Infrastructure – part 4: error loggingExtending MySQL using the Component Infrastructure – part 5: privilegesBefore MySQL 8.0, to add a feature to MySQL, writing a plugin was the only way. Now it’s possible to quickly extend MySQL Server by writing a component.
The MySQL Component Infrastructure is designed to overcome some of the architectural issues of the plugin subsystem, namely:
plugins can only “talk” to the server and not with other pluginsplugins have access to the server symbols and can call them directly (no encapsulation)there’s no explicit set of dependencies of a plugin, thus it’s hard to initialize them properlyplugins require a running server to operateThis article is the first of a series about writing our first usable component.
Our Component
To show how to create a component, I didn’t want to create the usual “hello world” example.
Recently, I got a question about how is it possible to deal with Viruses in MySQL ? Usually, the data should be scanned before being inserted on the database of course. But, yes, it could be a good idea to also have the possibility to scan data stored in MySQL.
Generally, a anti-virus is scanning files on the filesystem. But that doesn’t work when compression or encryption is used.
This is the same table with the EIRCAR TEST virus stored in one column:
Standard InnoDB Table:
[root@imac virus]# clamscan t1.ibd
/var/lib/mysql/virus/t1.ibd: {HEX}EICAR.TEST.3.UNOFFICIAL FOUND
----------- SCAN SUMMARY -----------
Known viruses: 8763291
Engine version: 0.103.4
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 0.11 MB
Data read: 0.11 MB (ratio 1.00:1)
Time: 15.812 sec (0 m 15 s)
Start Date: 2021:12:21 10:44:28
End Date: 2021:12:21 10:44:44
Compressed InnoDB Table:
mysql> alter table t1 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
[root@imac virus]# clamscan t1.ibd
/var/lib/mysql/virus/t1.ibd: OK
----------- SCAN SUMMARY -----------
Known viruses: 8763291
Engine version: 0.103.4
Scanned directories: 0
Scanned files: 1
Infected files: 0
Data scanned: 0.11 MB
Data read: 0.05 MB (ratio 2.00:1)
Time: 16.338 sec (0 m 16 s)
Start Date: 2021:12:21 11:00:58
End Date: 2021:12:21 11:01:15
Encrypted InnoDB Table:
mysql> alter table t1 encryption='y';
[root@imac virus]# clamscan t1.ibd
/var/lib/mysql/virus/t1.ibd: OK
----------- SCAN SUMMARY -----------
Known viruses: 8763291
Engine version: 0.103.4
Scanned directories: 0
Scanned files: 1
Infected files: 0
Data scanned: 0.22 MB
Data read: 0.11 MB (ratio 2.00:1)
Time: 15.990 sec (0 m 15 s)
Start Date: 2021:12:21 10:53:58
End Date: 2021:12:21 10:54:14
As you can see, the same virus stored in the table is not detected while scanning the .idb file on the filesystem when the tablespace is compressed and/or encrypted.
Therefor, the component we will create through this series will scan data for known viruses using ClamAV library installed on the same server as MySQL.
ClamAV® is an open-source (GPL) anti-virus engine used in a variety of situations, including email and web scanning, and endpoint security. It provides many utilities for users, including a flexible and scalable multi-threaded daemon, a command-line scanner and an advanced tool for automatic database updates.
Component Functionalities
Our component will create a function (similar to previous User Defined Function) to scan the data sent as parameter: virus_scan().
Our component will also create a new privilege required to use the new function: VIRUS_SCAN.
Our component will also write messages to the MySQL Server’s error log.
We will also add a second function to reload the ClamAV engine in case of a virus database update: virus_reload_engine().
And finally, our component will create two status variables to store the clamav total signatures loaded and the amount of eventual viruses found: viruscan.clamav_signature & viruscan_virus_found.
Development Requirements
To be able to create our component, we need to have the MySQL Server source (from GitHub) and clamav-devel and clamav-lib.
clamav-lib will also be required on the MySQL Server where the component will be installed.
As teaser this is an overview of our final component:
Conclusion
To prepare the next article, you can already start to download the source of MySQL Server.
In our next article we will setup your development environment and build MySQL from source.
Enjoy MySQL and get ready to extend it ! [Less]
|
Posted
over 3 years
ago
by
Frederic Descamps
This post is the first post of a series of articles on extending MySQL with the Component Infrastructure, the list above will be updated as new articles are published:
Extending MySQL using the Component Infrastructure – part 1Extending MySQL using
... [More]
the Component Infrastructure – part 2: building the serverExtending MySQL using the Component Infrastructure – part 3: component servicesBefore MySQL 8.0, to add a feature to MySQL, writing a plugin was the only way. Now it’s possible to quickly extend MySQL Server by writing a component.
The MySQL Component Infrastructure is designed to overcome some of the architectural issues of the plugin subsystem, namely:
plugins can only “talk” to the server and not with other pluginsplugins have access to the server symbols and can call them directly (no encapsulation)there’s no explicit set of dependencies of a plugin, thus it’s hard to initialize them properlyplugins require a running server to operateThis article is the first of a series about writing our first usable component.
Our Component
To show how to create a component, I didn’t want to create the usual “hello world” example.
Recently, I got a question about how is it possible to deal with Viruses in MySQL ? Usually, the data should be scanned before being inserted on the database of course. But, yes, it could be a good idea to also have the possibility to scan data stored in MySQL.
Generally, a anti-virus is scanning files on the filesystem. But that doesn’t work when compression or encryption is used.
This is the same table with the EIRCAR TEST virus stored in one column:
Standard InnoDB Table:
[root@imac virus]# clamscan t1.ibd
/var/lib/mysql/virus/t1.ibd: {HEX}EICAR.TEST.3.UNOFFICIAL FOUND
----------- SCAN SUMMARY -----------
Known viruses: 8763291
Engine version: 0.103.4
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 0.11 MB
Data read: 0.11 MB (ratio 1.00:1)
Time: 15.812 sec (0 m 15 s)
Start Date: 2021:12:21 10:44:28
End Date: 2021:12:21 10:44:44
Compressed InnoDB Table:
mysql> alter table t1 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
[root@imac virus]# clamscan t1.ibd
/var/lib/mysql/virus/t1.ibd: OK
----------- SCAN SUMMARY -----------
Known viruses: 8763291
Engine version: 0.103.4
Scanned directories: 0
Scanned files: 1
Infected files: 0
Data scanned: 0.11 MB
Data read: 0.05 MB (ratio 2.00:1)
Time: 16.338 sec (0 m 16 s)
Start Date: 2021:12:21 11:00:58
End Date: 2021:12:21 11:01:15
Encrypted InnoDB Table:
mysql> alter table t1 encryption='y';
[root@imac virus]# clamscan t1.ibd
/var/lib/mysql/virus/t1.ibd: OK
----------- SCAN SUMMARY -----------
Known viruses: 8763291
Engine version: 0.103.4
Scanned directories: 0
Scanned files: 1
Infected files: 0
Data scanned: 0.22 MB
Data read: 0.11 MB (ratio 2.00:1)
Time: 15.990 sec (0 m 15 s)
Start Date: 2021:12:21 10:53:58
End Date: 2021:12:21 10:54:14
As you can see, the same virus stored in the table is not detected while scanning the .idb file on the filesystem when the tablespace is compressed and/or encrypted.
Therefor, the component we will create through this series will scan data for known viruses using ClamAV library installed on the same server as MySQL.
ClamAV® is an open-source (GPL) anti-virus engine used in a variety of situations, including email and web scanning, and endpoint security. It provides many utilities for users, including a flexible and scalable multi-threaded daemon, a command-line scanner and an advanced tool for automatic database updates.
Component Functionalities
Our component will create a function (similar to previous User Defined Function) to scan the data sent as parameter: virus_scan().
Our component will also create a new privilege required to use the new function: VIRUS_SCAN.
Our component will also write messages to the MySQL Server’s error log.
We will also add a second function to reload the ClamAV engine in case of a virus database update: virus_reload_engine().
And finally, our component will create two status variables to store the clamav total signatures loaded and the amount of eventual viruses found: viruscan.clamav_signature & viruscan_virus_found.
Development Requirements
To be able to create our component, we need to have the MySQL Server source (from GitHub) and clamav-devel and clamav-lib.
clamav-lib will also be required on the MySQL Server where the component will be installed.
As teaser this is an overview of our final component:
Conclusion
To prepare the next article, you can already start to download the source of MySQL Server.
In our next article we will setup your development environment and build MySQL from source.
Enjoy MySQL and get ready to extend it ! [Less]
|