| description | Reference for the codeql database create command |
|---|
The codeql database create command is used to create CodeQL databases from source code repositories. This can take a long time, depending upon the size of the codebase from which the data(base) is to be extracted.
The following is an example use of the command for creating a database from a Java project:
$ codeql database create --language=java --source-root=/path/to/project mydbThe codeql database create command can also be used with different language and build configurations:
# Multiple languages
$ codeql database create --language=java,javascript --source-root=. mydb
# With custom build command for compiled languages
$ codeql database create --language=cpp --command="make all" mydb
# Auto-build mode
$ codeql database create --language=java --build-mode=autobuild mydbRun codeql database create --help for more information.
Run codeql database create --help --verbose for much more information.
codeql resolve extractor- Resolve which extractor to use for a language
codeql database analyze- Analyze the created database with queriescodeql query run- Run individual queries against the databasecodeql resolve database- Resolve the paths of created databases
codeql database create [OPTIONS] -- <database>Create a CodeQL database by analyzing source code. The database creation process extracts semantic information from source code, enabling subsequent query analysis. Supports multiple programming languages and build modes.
<database>- Mandatory Path where the new database will be created
--language=<lang>[,<lang>...]- Programming languages to analyze (auto-detected from GitHub repos if omitted with GITHUB_TOKEN)--build-mode=<mode>- Build mode for database creation:none: No building required (C#, Java, JavaScript/TypeScript, Python, Ruby)autobuild: Automatic build detection (C/C++, C#, Go, Java/Kotlin, Swift)manual: Manual build command (C/C++, C#, Go, Java/Kotlin, Swift)
-s, --source-root=<dir>- Root source code directory (default: current directory)-c, --command=<command>- Build command for compiled languages
-j, --threads=<num>- Threads for import operation (default: 1, 0 = cores, -N = leave N cores)-M, --ram=<MB>- Memory for import operation
--no-cleanup- Advanced Suppress database cleanup after finalization (debugging)--no-pre-finalize- Advanced Skip pre-finalize script from extractor--[no-]skip-empty- Advanced Warn instead of failing for empty databases--[no-]linkage-aware-import- Advanced Control linkage-aware import (default: enabled)
--[no-]calculate-baseline- Calculate baseline information about analyzed code--[no-]sublanguage-file-coverage- GitHub.com/GHES 3.12+ Use sub-language file coverage
--search-path=<dir>[:<dir>...]- Directories containing extractor packs-O, --extractor-option=<name=value>- Set extractor options--extractor-options-file=<file>- JSON/YAML file with extractor options
-a, --github-auth-stdin- Accept GitHub Apps token for language auto-detection-g, --github-url=<url>- GitHub instance URL (auto-detected from checkout)
--working-dir=<dir>- Advanced Directory for build command execution--no-run-unnecessary-builds- Advanced Only run builds when extractors need them--no-tracing- Advanced Don't trace build command--extra-tracing-config=<file>- Advanced Custom tracer configuration
# Python, JavaScript, Ruby
codeql database create --language=python mydb# Java, C#, Go with automatic build detection
codeql database create --language=java --build-mode=autobuild mydb# C/C++ with custom build command
codeql database create --language=cpp --command="make all" mydbcodeql database create --language=java --source-root=/path/to/project mydbcodeql database create --language=java,javascript --source-root=. mydbcodeql database create --language=cpp --command="cmake --build build/" mydb# Requires GITHUB_TOKEN environment variable
codeql database create --source-root=/path/to/repo mydbcodeql database create --language=java --threads=8 --ram=16384 mydbcodeql database create --language=java --extractor-option=java.buildtools.maven.M2_HOME=/usr/local/maven mydb- Analyzing source code repositories for security vulnerabilities
- Setting up databases for custom query development
- CI/CD integration for continuous security analysis
- Research and investigation of codebases
- Preparing data for bulk query analysis
- Complete CodeQL database in specified directory
- Extraction logs and progress information
- Database finalization and cleanup
- Error messages for build or extraction failures
mydb/
├── codeql-database.yml # Database metadata
├── db-<language>/ # Language-specific data
├── log/ # Extraction logs
├── working/ # Temporary working files (cleaned up)
└── src.zip # Source code archive
codeql database analyze- Analyze created databasescodeql query run- Run individual queries against databasescodeql pack install- Install query dependencies before analysis