一、登录数据库
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';