在Bash里使用交互式命令连接MySQL数据库,并执行一次查询

首先,我们是使用一台Linux终端来连接远程服务器上的MySql数据库,所以操作系统上需要安装客户端。

# yum install mysql


注意,书写安装的是MySQL, 可实际安装的确是MariaDB, 这后面的故事可以看看参考资料里的知乎里的一篇文章。


之后,使用命令来连接数据库。

# mysql -h 10.XXX.XXX.150 -u root -D performance_data -p


连上数据库之后,就可以在mysql shell里运行命令了。

MySQL [performance_data]> show tables;

MySQL [performance_data]> select id, automation_label, description from hardware where automation_label = 'f8101';


注意,MySQL的命令之后需要输入分号,单纯的换行是不能触发命令的执行的。


参考资料

=============

YUM COMMAND CHEAT SHEET

https://access.redhat.com/sites/default/files/attachments/rh_yum_cheatsheet_1214_jcs_print-1.pdf

Yum Command Fails with “Another app is currently holding the yum lock” in CentOS/ RHEL 7

https://www.thegeekdiary.com/yum-command-fails-with-another-app-is-currently-holding-the-yum-lock-in-centos-rhel-7/

How to execute MySQL queries from command line/Bash shell ?

https://hoststud.com/resources/how-to-execute-mysql-queries-from-command-line-bash-shell.136/

How to Run MySQL/MariaDB Queries Directly from the Linux Command Line

https://www.tecmint.com/run-execute-mysql-mariadb-queries-directly-linux-commandline/

MySQL CLI Cheatsheet

https://gist.github.com/hofmannsven/9164408

CentOS 7为什么放弃了MySQL,而改使用MariaDB?

https://www.zhihu.com/question/41832866

posted on   中道学友  阅读(481)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2009-09-10 归并排序

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

技术追求准确,态度积极向上

点击右上角即可分享
微信分享提示