mysql客户端语法

mysql -u {mysql-user} -p {mysql-password} -h {mysql-server}

其中:

  • -u {mysql-user}:指定MySQL用户名。
  • -p {mysql-password}:指定密码,连接到数据库服务器时使用指定的密码。如果未提供密码,则会以交互方式要求输入密码。
  • -h {mysql-server}:连接到指定的主机(远程或本地)

使用jack用户登录到远程MySQL服务器

$ mysql -u jack -h mysql.onitroad.com -p

输出示例:

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

在mysql>提示符下可以执行sql语句。
例如,查看test数据库中的数据表:

USE test;
SHOW TABLES;

会话示例:

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 31855130
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use nqod;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_nqod |
+----------------+
| article        | 
| classify       | 
+----------------+
2 rows in set (0.00 sec)

mysql> \q
Bye

要退出mysql客户端,请输入quit或\ q:

quit

或者

\q

批处理模式

还可以在脚本文件(批处理文件)中执行SQL语句,如下所示:

mysql database_name < input.script.sql > output.file
mysql -u user -p'password' database_name < input.script.sql > output.file
如何从终端访问MySQL服务器

如何使用命令行访问mysql服务器?

日期:2019-11-20 08:52:03 来源:oir作者:oir