{"id":18806738,"url":"https://github.com/lefred/mysql-component-viruscan","last_synced_at":"2025-04-11T06:09:10.174Z","repository":{"id":43840349,"uuid":"449664143","full_name":"lefred/mysql-component-viruscan","owner":"lefred","description":"Extending MySQL using the Component Infrastructure - Code example","archived":false,"fork":false,"pushed_at":"2024-01-23T19:46:53.000Z","size":56,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-29T21:27:14.292Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lefred.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-19T11:29:57.000Z","updated_at":"2024-08-18T14:45:03.000Z","dependencies_parsed_at":"2024-11-07T22:49:34.319Z","dependency_job_id":"6eb2e97d-761c-43dd-9c68-60090721fa7f","html_url":"https://github.com/lefred/mysql-component-viruscan","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-viruscan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-viruscan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-viruscan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-viruscan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lefred","download_url":"https://codeload.github.com/lefred/mysql-component-viruscan/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239742416,"owners_count":19689309,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T22:49:26.218Z","updated_at":"2025-02-19T22:13:27.282Z","avatar_url":"https://github.com/lefred.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mysql-component-viruscan\nExtending MySQL using the Component Infrastructure - Code example\n\nThis component is an example used during the Extending MySQL using the Component Infrastructure series published on https://lefred.be:\n\n* [Extending MySQL using the Component Infrastructure – part 1](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-1/)\n* [Extending MySQL using the Component Infrastructure – part 2: building the server](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-2-building-the-server/)\n* [Extending MySQL using the Component Infrastructure – part 3: component services](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-3-component-services/)\n* [Extending MySQL using the Component Infrastructure – part 4: error logging](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-4-error-logging/)\n* [Extending MySQL using the Component Infrastructure – part 5: privileges](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-5-privileges/)\n* [Extending MySQL using the Component Infrastructure – part 6: functions](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-6-functions/)\n* [Extending MySQL using the Component Infrastructure – part 7: messages to users](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-7-messages-to-users/)\n* [Extending MySQL using the Component Infrastructure – part 8: linking a third party library](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-8-linking-a-third-party-library/)\n* [Extending MySQL using the Component Infrastructure – part 9: adding a new function](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-9-adding-a-new-function/)\n* [Extending MySQL using the Component Infrastructure – part 10: status variables](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-10-status-variables/)\n* [Extending MySQL using the Component Infrastructure – part 11: performance_schema table](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-11-performance_schema-table/)\n* [Extending MySQL using the Component Infrastructure – part 12 : instrument your code](https://lefred.be/content/extending-mysql-using-the-component-infrastructure-part-12-instrument-your-code/)\n\n# How to use\n\n## Installation\n\n```\n$ sudo rpm -ivh mysql-community-component-viruscan-8.1.0-10.fc38.x86_64.rpm\n$ mysqlsh mysql://root@localhost\n\nMySQL \u003e install component \"file://component_viruscan\";\nQuery OK, 0 rows affected (0.0276 sec)\n\nMySQL \u003e select * from performance_schema.error_log where subsystem=\"server\" and data like 'Component viruscan%';\n+----------------------------+-----------+-------+------------+-----------+-----------------------------------------------------------------------------------------------+\n| LOGGED                     | THREAD_ID | PRIO  | ERROR_CODE | SUBSYSTEM | DATA                                                                                          |\n+----------------------------+-----------+-------+------------+-----------+-----------------------------------------------------------------------------------------------+\n| 2023-08-16 14:45:58.781052 |         9 | Note  | MY-011071  | Server    | Component viruscan reported: 'initializing...'                                                |\n| 2023-08-16 14:45:58.781499 |         9 | Note  | MY-011071  | Server    | Component viruscan reported: 'Status variable(s) registered'                                  |\n| 2023-08-16 14:45:58.781627 |         9 | Note  | MY-011071  | Server    | Component viruscan reported: 'ClamAV 1.0.1 intialized'                                        |\n| 2023-08-16 14:45:58.783058 |         9 | Error | MY-011071  | Server    | Component viruscan reported: 'failure loading clamav databases: Can't open file or directory' |\n| 2023-08-16 14:45:58.783957 |         9 | Note  | MY-011071  | Server    | Component viruscan reported: 'clamav engine loaded with signatureNum 0 from /var/lib/clamav'  |\n| 2023-08-16 14:45:58.783993 |         9 | Note  | MY-011071  | Server    | Component viruscan reported: 'new privilege 'VIRUS_SCAN' has been registered successfully.'   |\n| 2023-08-16 14:45:58.785867 |         9 | Note  | MY-011071  | Server    | Component viruscan reported: 'PFS table has been registered successfully.'                    |\n+----------------------------+-----------+-------+------------+-----------+-----------------------------------------------------------------------------------------------+\n7 rows in set (0.0067 sec)\n```\n\nPay attention that there is an error reported by the clamav engine.\nYou can also notice the value of the status variable `viruscan.clamav_signatures` being `0`.\n\nRun: \n\n```\n$ sudo freshclam\n```\n\nAnd then you need to reload the engine:\n\n```\nMySQL \u003e select virus_reload_engine();\n```\n\n## UDF Functions\n\n```\nMySQL \u003e select * from performance_schema.user_defined_functions \n            where udf_name like 'virus%';\n+---------------------+-----------------+----------+-------------+-----------------+\n| UDF_NAME            | UDF_RETURN_TYPE | UDF_TYPE | UDF_LIBRARY | UDF_USAGE_COUNT |\n+---------------------+-----------------+----------+-------------+-----------------+\n| virus_reload_engine | char            | function | NULL        |               1 |\n| virus_scan          | char            | function | NULL        |               1 |\n+---------------------+-----------------+----------+-------------+-----------------+\n2 rows in set (0.0008 sec)\n```\n\n## Usage\n\n```\nMySQL \u003e select virus_scan(\"lefred\");\nERROR: 1227 (42000): Access denied; you need (at least one of) the VIRUS_SCAN privilege(s) for this operation\n\nMySQL \u003e grant VIRUS_SCAN on *.* to root;\nQuery OK, 0 rows affected (0.0150 sec)\n\nMySQL \u003e select virus_scan(\"lefred\");\n+-----------------------+\n| virus_scan(\"lefred\")  |\n+-----------------------+\n| clean: no virus found |\n+-----------------------+\n1 row in set (0.0013 sec)\n\nMySQL \u003e show global status like 'viruscan.%';\n+--------------------------------+-------+\n| Variable_name                  | Value |\n+--------------------------------+-------+\n| viruscan.clamav_engine_version | 1.0.1 |\n| viruscan.clamav_signatures     | 0     |\n| viruscan.virus_found           | 0     |\n+--------------------------------+-------+\n3 rows in set (0.0026 sec)\n\nselect virus_scan(\"X5O!P%@AP[4\\\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*\");\n+-------------------------------------------------------------------------------------+\n| virus_scan(\"X5O!P%@AP[4\\\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*\") |\n+-------------------------------------------------------------------------------------+\n| Eicar-Signature                                                                     |\n+-------------------------------------------------------------------------------------+\n1 row in set (0.0083 sec)\n\nMySQL \u003e show global status like 'viruscan.virus_found';\n+----------------------+-------+\n| Variable_name        | Value |\n+----------------------+-------+\n| viruscan.virus_found | 1     |\n+----------------------+-------+\n1 row in set (0.0021 sec)\n```\n\n## Performance_Schema \n \n```\nMySQL \u003e select * from performance_schema.viruscan_matches;\n+---------------------+-----------------+------+-----------+-------------+------------+\n| LOGGED              | VIRUS           | USER | HOST      | CLAMVERSION | SIGNATURES |\n+---------------------+-----------------+------+-----------+-------------+------------+\n| 2023-08-16 15:09:24 | Eicar-Signature | root | localhost | 1.0.1       |    8671805 |\n+---------------------+-----------------+------+-----------+-------------+------------+\n1 row in set (0.0007 sec)\n```\n## Updating the virus database\n\nAs for the installation, you need to upgrade the clamav engine and database using `freshclam` and then reload the engine and verify the version:\n\n```\nMySQL \u003e select virus_reload_engine();\n+--------------------------------------------------------------------+\n| virus_reload_engine()                                              |\n+--------------------------------------------------------------------+\n| ClamAV engine reloaded with new virus database: 8671805 signatures |\n+--------------------------------------------------------------------+\n1 row in set (10.8586 sec)\n\nMySQL \u003e select * from performance_schema.error_log \n        where subsystem=\"server\" and data like 'Component viruscan%' \n        order by logged desc limit 1\\G\n*************************** 1. row ***************************\n    LOGGED: 2023-08-16 15:07:29.675698\n THREAD_ID: 9\n      PRIO: Note\nERROR_CODE: MY-011071\n SUBSYSTEM: Server\n      DATA: Component viruscan reported: 'clamav engine loaded with signatureNum 8671805 from /var/lib/clamav'\n1 row in set (0.0066 sec)\n\nMySQL \u003e show global status like 'viruscan.clamav_%';\n+--------------------------------+---------+\n| Variable_name                  | Value   |\n+--------------------------------+---------+\n| viruscan.clamav_engine_version | 1.0.1   |\n| viruscan.clamav_signatures     | 8671805 |\n+--------------------------------+---------+\n2 rows in set (0.0021 sec)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flefred%2Fmysql-component-viruscan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flefred%2Fmysql-component-viruscan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flefred%2Fmysql-component-viruscan/lists"}