Linux command
mysql 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Connect to database
mysql -u [username] -p [database]
Connect to remote host
mysql -h [hostname] -u [username] -p [database]
Execute SQL command
mysql -u [user] -p -e "[SELECT * FROM table]" [database]
Execute SQL file
mysql -u [user] -p [database] < [script.sql]
Connect with specific port
mysql -h [host] -P [3306] -u [user] -p
Import database dump
mysql -u [user] -p [database] < [dump.sql]
说明
mysql is the MySQL command-line client. It connects to MySQL/MariaDB servers. The tool executes SQL queries. Provides interactive and batch modes.
参数
- -h _HOST_
- Server hostname.
- -u _USER_
- Username.
- -p _PASSWORD_
- Password (prompts if empty).
- -P _PORT_
- Port number.
- -e _COMMAND_
- Execute SQL and exit.
- --help
- Display help information.
FAQ
What is the mysql command used for?
mysql is the MySQL command-line client. It connects to MySQL/MariaDB servers. The tool executes SQL queries. Provides interactive and batch modes.
How do I run a basic mysql example?
Run `mysql -u [username] -p [database]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -h _HOST_ do in mysql?
Server hostname.