如何列出MySQL / MariaDB数据库?

MySQL is a very popular opensource database. MySQL is created by MySQL AB a Swedish company and then bought by Sun. Sun is bought by Oracle and MySQL is currently owned by Oracle. MySQL is very popular in the opensource community. In this post, we will look at how to list databases in MySQL.

MySQL是一个非常流行的开源数据库。 MySQL由瑞典公司MySQL AB创建,然后被Sun收购。 Sun被Oracle收购,MySQL目前归Oracle所有。 MySQL在开源社区中非常流行。 在本文中,我们将研究如何在MySQL中列出数据库。

检查MySQL服务状态 (Check MySQL Service Status)

We need to be sure that MySQL daemon is running we will check with following systemctl command. The MySQL service name is the same mysql.

我们需要确保MySQL守护程序正在运行,我们将使用以下systemctl命令进行检查。 MySQL服务名称与mysql相同。

$ systemctl status mysql
Check MySQL Service Status
Check MySQL Service Status
检查MySQL服务状态

连接MySQL服务器(Connect MySQL Server)

We will use MySQL server tools to connect MySQL daemon. mysql is the most used command-line tool to connect and manage a MySQL server. We will connect server by running mysql command with sudo which means with root privileges.

我们将使用MySQL服务器工具连接MySQL守护程序。 mysql是连接和管理MySQL服务器的最常用的命令行工具。 我们将通过使用sudo运行mysql命令来连接服务器,这意味着具有root特权。

$ sudo mysql -u root
Connect MySQL Server
Connect MySQL Server
连接MySQL服务器

Another way to connect MySQL daemon is by providing a password with -p parameter

连接MySQL守护程序的另一种方法是通过-p提供密码 参数

$ sudo mysql -u root -p
Connect MySQL Server
Connect MySQL Server
连接MySQL服务器

MySQL列表/显示数据库(MySQL List/Show  Databases)

We will usage MySQL command show databases to list databases. Using semicolon at the end of the command is important otherwise the command will fail.

我们将使用MySQL命令show databases来列出数据库。 在命令末尾使用分号非常重要,否则命令将失败。

mysql> show databases;
MySQL List/Show  Databases
MySQL List/Show  Databases
MySQL列表/显示数据库

从Bash列出数据库而无需进入MySQL Shell(List Databases From Bash without Entering MySQL Shell)

We can list MySQL databases without entering the MySQL tool command line through bash. We will use a similar command to connect MySQL database but providing show database command as a parameter. We will use MySQL show databases.

我们可以列出MySQL数据库,而无需通过bash输入MySQL工具命令行。 我们将使用类似的命令连接MySQL数据库,但提供show database命令作为参数。 我们将使用MySQL show数据库。

$ sudo mysql -u root -e 'show databases;'
List Databases From Bash without Entering MySQL Shell
List Databases From Bash without Entering MySQL Shell
从Bash列出数据库而无需进入MySQL Shell

We have issued MySQL command with -e parameter. show databases; runs as a MySQL connect in the MySQL shell.

我们已经发布了带有-e参数MySQL命令。 显示数据库; 在MySQL Shell中作为MySQL连接运行。

$ sudo mysql -u root -h 192.168.122.211   -e 'show databases;'

Here is everything is similar to the previous example except hostname which is provided as -h 192.168.122.211We provide hostname as the remote host, not localhost. To connect remote host firewall must give access to the port and MySQL daemon should be listening specified IP’s interface.

除了提供为-h 192.168.122.211主机名之外,这一切都与前面的示例相似 我们提供主机名作为远程主机,而不是localhost。 要连接远程主机,防火墙必须提供对端口的访问权限,而MySQL守护程序应侦听指定IP的接口。

LEARN MORE  How To List MySQL Database Users?
了解更多如何列出MySQL数据库用户?

翻译自: https://www.poftut.com/list-mysql-mariadb-database/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值