数据库常用命令

本文介绍了如何使用命令行登录MySQL数据库,包括设置环境变量免密登录。接着展示了查询数据库和表的操作,如显示所有数据库、选择特定数据库以及查看表中的记录。最后,文章提到了删除操作,包括删除表和表中特定记录的语法。
摘要由CSDN通过智能技术生成

一、登录数据库

mysql -uroot -p  # -u用户名, -p跟密码
也可以在命令行export密码,这样后续就不需要输入密码了
export MYSQL_PWD=password

二、查询数据

注意每条语句后需要加;结尾,否则视为命令未结束

显示当前所有数据库:show databases;

选择数据库:use databasename;

显示当前数据库的所有表:show tables;

显示表中的一条记录:select * from gerrit limit 1;

[root@node02 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56085
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| azkaban            |
| devops             |
| hive               |
| mall               |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
8 rows in set (0.00 sec)

mysql> use devops;
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_devops |
+------------------+
| gerrit           |
+------------------+
1 row in set (0.00 sec)

mysql>

三、删除

删除表

drop table table_name;

删除gerrit表中project名为test的记录

delete from gerrit where project = 'test';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值