Linux command
mariadb 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Connect to database
mariadb -u [user] -p [database]
Connect to remote server
mariadb -h [hostname] -u [user] -p [database]
Execute SQL command
mariadb -u [user] -p -e "[SELECT * FROM table]" [database]
Execute SQL file
mariadb -u [user] -p [database] < [script.sql]
Connect with socket
mariadb -S [/var/run/mysqld/mysqld.sock] -u [user] -p
Export query to file
mariadb -u [user] -p -e "[SELECT * FROM table]" [database] > [output.txt]
Connect with SSL
mariadb --ssl -u [user] -p [database]
Import SQL dump while showing progress
mariadb -u [user] -p [database] < [dump.sql]
说明
mariadb is the command-line client for MariaDB database server. It provides an interactive SQL shell and can execute commands from files or command line. The client connects to MariaDB or MySQL servers, as MariaDB maintains wire protocol compatibility. Interactive mode provides command history, editing, and tab completion. Batch mode (-B) produces tab-separated output suitable for scripting. Combined with -N to skip headers, output can be processed by other tools. Safe updates mode prevents UPDATE and DELETE without WHERE clauses, protecting against accidental data loss. SSL connections encrypt traffic between client and server. Certificate verification can be configured for production environments. The client supports pipelining SQL from files, enabling automated database migrations and backups restoration.
参数
- -u _USER_, --user _USER_
- Username for connection.
- -p_PASSWORD_, --password=_PASS_
- Prompt for or specify password.
- -h _HOST_, --host _HOST_
- Server hostname.
- -P _PORT_, --port _PORT_
- Server port.
- -S _SOCKET_, --socket _SOCKET_
- Unix socket file.
- -D _DB_, --database _DB_
- Database to use.
- -e _CMD_, --execute _CMD_
- Execute command and exit.
- -B, --batch
- Batch mode (no formatting).
- -N, --skip-column-names
- Don't show column names.
- -t, --table
- Output as table.
- --ssl
- Enable SSL for the connection.
- --quick
- Don't cache result set, print row by row. Useful for large result sets.
- -A, --no-auto-rehash
- Disable auto-completion for faster startup.
- --safe-updates
- Prevent accidental large updates.
- -v, --verbose
- Verbose output.
FAQ
What is the mariadb command used for?
mariadb is the command-line client for MariaDB database server. It provides an interactive SQL shell and can execute commands from files or command line. The client connects to MariaDB or MySQL servers, as MariaDB maintains wire protocol compatibility. Interactive mode provides command history, editing, and tab completion. Batch mode (-B) produces tab-separated output suitable for scripting. Combined with -N to skip headers, output can be processed by other tools. Safe updates mode prevents UPDATE and DELETE without WHERE clauses, protecting against accidental data loss. SSL connections encrypt traffic between client and server. Certificate verification can be configured for production environments. The client supports pipelining SQL from files, enabling automated database migrations and backups restoration.
How do I run a basic mariadb example?
Run `mariadb -u [user] -p [database]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -u _USER_, --user _USER_ do in mariadb?
Username for connection.