如何列出MySQL / MariaDB数据库

I have some MySQL databases. I have no previous experience with MySQL. How can we list existing databases with bash?MySQL and MariaDB are using the same code base and tools. So we can use the following instructions to list MariaDB too.

我有一些MySQL数据库。 我以前没有使用MySQL的经验。 我们如何使用bash列出现有数据库?MySQL和MariaDB使用相同的代码库和工具。 因此,我们也可以使用以下说明来列出MariaDB。

检查数据库服务 (Check Database Service)

First we will check if the MySQL or MariaDB database service is running properly with the systemctl command like below.

首先,我们将使用systemctl命令检查MySQL或MariaDB数据库服务是否正常运行,如下所示。

$ systemctl status mysql
Check Database Service
Check Database Service
检查数据库服务

As we can see from systemctl output the database service is working properly.

systemctl输出中可以看到,数据库服务正常运行。

登录到MySQL Interactive Shell (Login To MySQL Interactive Shell)

In order to list databases, we need to connect and login to MySQL interactive shell. We will use mysql tool by providing the user root

为了列出数据库,我们需要连接并登录到MySQL交互式shell。 我们将通过提供root用户来使用mysql工具

$ mysql -u root
Login To MySQL Interactive Shell
Login To MySQL Interactive Shell
登录到MySQL Interactive Shell

Now we will use show databases command to list existing databases. ; is important which means end of the command.

现在,我们将使用show databases命令列出现有数据库。 ; 重要,这意味着命令结束。

> show databases;
List Databases
List Databases
列出数据库

We can see that there is 5 databases in this MySQL Server.

我们可以看到该MySQL服务器中有5个数据库。

列出而不输入MySQL Shell (List Without Entering MySQL Shell)

Entering MySQL database server and running show database command may a trivial task. We can directly run show database command from the Linux bash shell like below by using -e option.

进入MySQL数据库服务器并运行show database命令可能是一项琐碎的任务。 我们可以使用-e选项从Linux bash shell直接运行show database命令,如下所示。

$ sudo mysql -u root -e "show databases;"
List Without Entering MySQL Shell
List Without Entering MySQL Shell
列出而不输入MySQL Shell

列表而不从远程数据库服务器输入MySQL Shell (List Without Entering MySQL Shell From Remote Database Server)

If we want to list databases from a remote database server we need to provide the remote system hostname or IP address. In this example, we will use the option -h which is a short form of host. We will connect remote server 192.168.142.144.

如果要从远程数据库服务器列出数据库,则需要提供远程系统的主机名或IP地址。 在此示例中,我们将使用选项-h ,它是host的简写形式。 我们将连接远程服务器192.168.142.144。

$ mysql -u root -h 192.168.142.144 -e "show databases;"
LEARN MORE  How To Access MySQL Database From Java Applications?
了解更多如何从Java应用程序访问MySQL数据库?

翻译自: https://www.poftut.com/list-mysqlmariadb-databases/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值