2014-05-08 23:37:47 +04:00
|
|
|
# mysql
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
> The MySQL command-line tool.
|
2019-06-03 03:06:36 +03:00
|
|
|
> More information: <https://www.mysql.com/>.
|
2014-05-08 23:37:47 +04:00
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Connect to a database:
|
2014-05-08 23:37:47 +04:00
|
|
|
|
|
|
|
`mysql {{database_name}}`
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Connect to a database, user will be prompted for a password:
|
2014-05-08 23:37:47 +04:00
|
|
|
|
2015-12-29 01:49:37 +03:00
|
|
|
`mysql -u {{user}} --password {{database_name}}`
|
2014-05-08 23:37:47 +04:00
|
|
|
|
2016-01-18 01:22:16 +03:00
|
|
|
- Connect to a database on another host:
|
2015-12-29 11:52:29 +03:00
|
|
|
|
2016-01-18 01:22:16 +03:00
|
|
|
`mysql -h {{database_host}} {{database_name}}`
|
2014-05-08 23:37:47 +04:00
|
|
|
|
2018-02-07 20:22:52 +03:00
|
|
|
- Connect to a database through a Unix socket:
|
|
|
|
|
|
|
|
`mysql --socket {{path/to/socket.sock}}`
|
|
|
|
|
2016-01-07 20:31:27 +03:00
|
|
|
- Execute SQL statements in a script file (batch file):
|
2014-05-08 23:37:47 +04:00
|
|
|
|
2018-05-18 04:59:47 +03:00
|
|
|
`mysql -e "source {{filename.sql}}" {{database_name}}`
|
2020-03-10 15:33:52 +03:00
|
|
|
|
2020-08-02 19:48:22 +03:00
|
|
|
- Restore a database from a backup created with `mysqldump` (user will be prompted for a password):
|
2020-03-10 15:33:52 +03:00
|
|
|
|
|
|
|
`mysql --user {{user}} --password {{database_name}} < {{path/to/backup.sql}}`
|
|
|
|
|
|
|
|
- Restore all databases from a backup (user will be prompted for a password):
|
|
|
|
|
|
|
|
`mysql --user {{user}} --password < {{path/to/backup.sql}}`
|