|
| 1 | +--- |
| 2 | +title: MySQL |
| 3 | +--- |
| 4 | +MySQL can be automatically configured for your dev environment by Devbox via the built-in MySQL Plugin. This plugin will activate automatically when you install MySQL using `devbox add mysql80` or `devbox add mysql57`. |
| 5 | + |
| 6 | +[**Example Repo**](https://github.com/jetpack-io/devbox/tree/main/examples/databases/mysql) |
| 7 | + |
| 8 | +[](https://devbox.sh/github.com/jetpack-io/devbox/?folder=examples/databases/mysql) |
| 9 | + |
| 10 | +## Adding MySQL to your Shell |
| 11 | + |
| 12 | +`devbox add mysql80`, or in your `devbox.json` add |
| 13 | + |
| 14 | +```json |
| 15 | + "packages": [ |
| 16 | + "mysql80@latest" |
| 17 | + ] |
| 18 | +``` |
| 19 | + |
| 20 | +You can also install Mysql 5.7 by using `devbox add mysql57` |
| 21 | + |
| 22 | +You can manually add the MySQL Plugin to your `devbox.json` by adding it to your `include` list: |
| 23 | + |
| 24 | +```json |
| 25 | + "include": [ |
| 26 | + "plugin:mysql" |
| 27 | + ] |
| 28 | +``` |
| 29 | + |
| 30 | +## MySQL Plugin Support |
| 31 | + |
| 32 | +Devbox will automatically create the following configuration when you run `devbox add mysql80` or `devbox add mysql57`. You can view the full configuration by running `devbox info mysql` |
| 33 | + |
| 34 | + |
| 35 | +### Services |
| 36 | +* mysql |
| 37 | + |
| 38 | +You can use `devbox services up|stop mysql` to start or stop the MySQL Server. |
| 39 | + |
| 40 | +### Environment Variables |
| 41 | + |
| 42 | +```bash |
| 43 | +MYSQL_BASEDIR=.devbox/nix/profile/default |
| 44 | +MYSQL_HOME=./.devbox/virtenv/mysql/run |
| 45 | +MYSQL_DATADIR=./.devbox/virtenv/mysql/data |
| 46 | +MYSQL_UNIX_PORT=./.devbox/virtenv/mysql/run/mysql.sock |
| 47 | +MYSQL_PID_FILE=./.devbox/mysql/run/mysql.pid |
| 48 | +``` |
| 49 | + |
| 50 | +### Files |
| 51 | + |
| 52 | +The plugin will also create the following helper files in your project's `.devbox/virtenv` folder: |
| 53 | + |
| 54 | +* mysql/flake.nix |
| 55 | +* mysql/setup_db.sh |
| 56 | +* mysql/process-compose.yaml |
| 57 | + |
| 58 | +These files are used to setup your database and service, and should not be modified |
| 59 | + |
| 60 | +### Notes |
| 61 | + |
| 62 | +* This plugin wraps mysqld to work in your local project. For more information, see the `flake.nix` created in your `.devbox/virtenv/mysql` folder. |
| 63 | +* This plugin will create a new database for your project in `MYSQL_DATADIR` if one doesn't exist on shell init. |
| 64 | +* You can use `mysqld` to manually start the server, and `mysqladmin -u root shutdown` to manually stop it |
| 65 | +* `.sock` filepath can only be maximum 100 characters long. You can point to a different path by setting the `MYSQL_UNIX_PORT` env variable in your `devbox.json` as follows: |
| 66 | + |
| 67 | +```json |
| 68 | +"env": { |
| 69 | + "MYSQL_UNIX_PORT": "/<some-other-path>/mysql.sock" |
| 70 | +} |
| 71 | +``` |
0 commit comments