# Using a MySQL server backend

Johannes Rainer

#### 30 April 2024

#### Package

ensembldb 2.28.0

# 1 Introduction

`ensembldb` uses by default, similar to other annotation packages in Bioconductor, a SQLite database backend, i.e. annotations are retrieved from file-based SQLite databases that are provided via packages, such as the `EnsDb.Hsapiens.v86` package. In addition, `ensembldb` allows to switch the backend from SQLite to MariaDB/MySQL and thus to retrieve annotations from a MySQL server instead. Such a setup might be useful for a lab running a well-configured MySQL server that would require installation of EnsDb databases only on the database server and not on the individual clients.

Note the code in this document is not executed during vignette generation as this would require access to a MySQL server.

# 2 Using `ensembldb` with a MySQL server

Installation of `EnsDb` databases in a MySQL server is straight forward - given that the user has write access to the server:

    library(ensembldb)
    ## Load the EnsDb package that should be installed on the MySQL server
    library(EnsDb.Hsapiens.v86)

    ## Call the useMySQL method providing the required credentials to create
    ## databases and inserting data on the MySQL server
    edb_mysql <- useMySQL(EnsDb.Hsapiens.v86, host = "localhost",
                          user = "userwrite", pass = "userpass")

    ## Use this EnsDb object
    genes(edb_mysql)

To use an `EnsDb` in a MySQL server without the need to install the corresponding R-package, the connection to the database can be passed to the `EnsDb` constructor function. With the resulting `EnsDb` object annotations can be retrieved from the MySQL database.

    library(ensembldb)
    library(RMariaDB)

    ## Connect to the MySQL database to list the databases.
    dbcon <- dbConnect(MariaDB(), host = "localhost", user = "readonly",
                       pass = "readonly")

    ## List the available databases
    listEnsDbs(dbcon)

    ## Connect to one of the databases and use that one.
    dbcon <- dbConnect(MariaDB(), host = "localhost", user = "readonly",
                       pass = "readonly", dbname = "ensdb_hsapiens_v75")
    edb <- EnsDb(dbcon)
    edb

# 3 Session information

    sessionInfo()

    ## R version 4.4.0 beta (2024-04-14 r86421)
    ## Platform: x86_64-apple-darwin20
    ## Running under: macOS Monterey 12.7.1
    ##
    ## Matrix products: default
    ## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
    ## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
    ##
    ## locale:
    ## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    ##
    ## time zone: America/New_York
    ## tzcode source: internal
    ##
    ## attached base packages:
    ## [1] grid      stats4    stats     graphics  grDevices utils     datasets
    ## [8] methods   base
    ##
    ## other attached packages:
    ##  [1] AnnotationHub_3.12.0
    ##  [2] BiocFileCache_2.12.0
    ##  [3] dbplyr_2.5.0
    ##  [4] BSgenome.Hsapiens.NCBI.GRCh38_1.3.1000
    ##  [5] BSgenome_1.72.0
    ##  [6] rtracklayer_1.64.0
    ##  [7] BiocIO_1.14.0
    ##  [8] Biostrings_2.72.0
    ##  [9] XVector_0.44.0
    ## [10] Gviz_1.48.0
    ## [11] EnsDb.Hsapiens.v86_2.99.0
    ## [12] ensembldb_2.28.0
    ## [13] AnnotationFilter_1.28.0
    ## [14] GenomicFeatures_1.56.0
    ## [15] AnnotationDbi_1.66.0
    ## [16] Biobase_2.64.0
    ## [17] GenomicRanges_1.56.0
    ## [18] GenomeInfoDb_1.40.0
    ## [19] IRanges_2.38.0
    ## [20] S4Vectors_0.42.0
    ## [21] BiocGenerics_0.50.0
    ## [22] BiocStyle_2.32.0
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] RColorBrewer_1.1-3          rstudioapi_0.16.0
    ##   [3] jsonlite_1.8.8              magrittr_2.0.3
    ##   [5] magick_2.8.3                rmarkdown_2.26
    ##   [7] zlibbioc_1.50.0             vctrs_0.6.5
    ##   [9] memoise_2.0.1               Rsamtools_2.20.0
    ##  [11] RCurl_1.98-1.14             base64enc_0.1-3
    ##  [13] tinytex_0.50                htmltools_0.5.8.1
    ##  [15] S4Arrays_1.4.0              progress_1.2.3
    ##  [17] curl_5.2.1                  SparseArray_1.4.0
    ##  [19] Formula_1.2-5               sass_0.4.9
    ##  [21] bslib_0.7.0                 htmlwidgets_1.6.4
    ##  [23] httr2_1.0.1                 cachem_1.0.8
    ##  [25] GenomicAlignments_1.40.0    mime_0.12
    ##  [27] lifecycle_1.0.4             pkgconfig_2.0.3
    ##  [29] Matrix_1.7-0                R6_2.5.1
    ##  [31] fastmap_1.1.1               GenomeInfoDbData_1.2.12
    ##  [33] MatrixGenerics_1.16.0       digest_0.6.35
    ##  [35] colorspace_2.1-0            Hmisc_5.1-2
    ##  [37] RSQLite_2.3.6               filelock_1.0.3
    ##  [39] fansi_1.0.6                 httr_1.4.7
    ##  [41] abind_1.4-5                 compiler_4.4.0
    ##  [43] withr_3.0.0                 bit64_4.0.5
    ##  [45] htmlTable_2.4.2             backports_1.4.1
    ##  [47] BiocParallel_1.38.0         DBI_1.2.2
    ##  [49] highr_0.10                  biomaRt_2.60.0
    ##  [51] rappdirs_0.3.3              DelayedArray_0.30.0
    ##  [53] rjson_0.2.21                tools_4.4.0
    ##  [55] foreign_0.8-86              nnet_7.3-19
    ##  [57] glue_1.7.0                  restfulr_0.0.15
    ##  [59] checkmate_2.3.1             cluster_2.1.6
    ##  [61] generics_0.1.3              gtable_0.3.5
    ##  [63] data.table_1.15.4           hms_1.1.3
    ##  [65] xml2_1.3.6                  utf8_1.2.4
    ##  [67] BiocVersion_3.19.1          pillar_1.9.0
    ##  [69] stringr_1.5.1               dplyr_1.1.4
    ##  [71] lattice_0.22-6              bit_4.0.5
    ##  [73] deldir_2.0-4                biovizBase_1.52.0
    ##  [75] tidyselect_1.2.1            knitr_1.46
    ##  [77] gridExtra_2.3               bookdown_0.39
    ##  [79] ProtGenerics_1.36.0         SummarizedExperiment_1.34.0
    ##  [81] xfun_0.43                   matrixStats_1.3.0
    ##  [83] stringi_1.8.3               UCSC.utils_1.0.0
    ##  [85] lazyeval_0.2.2              yaml_2.3.8
    ##  [87] evaluate_0.23               codetools_0.2-20
    ##  [89] interp_1.1-6                tibble_3.2.1
    ##  [91] BiocManager_1.30.22         cli_3.6.2
    ##  [93] rpart_4.1.23                munsell_0.5.1
    ##  [95] jquerylib_0.1.4             dichromat_2.0-0.1
    ##  [97] Rcpp_1.0.12                 png_0.1-8
    ##  [99] XML_3.99-0.16.1             parallel_4.4.0
    ## [101] ggplot2_3.5.1               blob_1.2.4
    ## [103] prettyunits_1.2.0           latticeExtra_0.6-30
    ## [105] jpeg_0.1-10                 bitops_1.0-7
    ## [107] VariantAnnotation_1.50.0    scales_1.3.0
    ## [109] purrr_1.0.2                 crayon_1.5.2
    ## [111] rlang_1.1.3                 KEGGREST_1.44.0