2025-03-14 21:59:59 -06:00
|
|
|
# mysql
|
|
|
|
|
|
2025-07-24 22:27:13 -06:00
|
|
|
> The MySQL tool.
|
2025-03-14 21:59:59 -06:00
|
|
|
> More information: <https://www.mysql.com/>.
|
|
|
|
|
|
|
|
|
|
- Connect to a database:
|
|
|
|
|
|
|
|
|
|
`mysql {{database_name}}`
|
|
|
|
|
|
|
|
|
|
- Connect to a database, user will be prompted for a password:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`mysql {{[-u|--user]}} {{user}} {{[-p|--password]}} {{database_name}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Connect to a database on another host:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`mysql {{[-h|--host]}} {{database_host}} {{database_name}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Connect to a database through a Unix socket:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`mysql {{[-S|--socket]}} {{path/to/socket.sock}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Execute SQL statements in a script file (batch file):
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`mysql {{[-e|--execute]}} "source {{filename.sql}}" {{database_name}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Restore a database from a backup created with `mysqldump` (user will be prompted for a password):
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`mysql {{[-u|--user]}} {{user}} {{[-p|--password]}} {{database_name}} < {{path/to/backup.sql}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Restore all databases from a backup (user will be prompted for a password):
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`mysql {{[-u|--user]}} {{user}} {{[-p|--password]}} < {{path/to/backup.sql}}`
|