redhat linux连接数据库命令行,如何在Linux和Windows上从命令行连接MySQL / MariaDB服务器?...

如何在Linux和Windows上从命令行连接MySQL / MariaDB服务器?

如何在Linux和Windows上从命令行连接MySQL / MariaDB服务器?

MySQL or MariaDB database servers can be managed in different ways. Generally, GUI tools are provided because of their easiness. But in some cases command line connection may be required to connect and management MySQL and MariaDB database server.

MySQL或MariaDB数据库服务器可以通过不同的方式进行管理。 通常,由于其易用性而提供了GUI工具。 但是在某些情况下,可能需要命令行连接才能连接和管理MySQL和MariaDB数据库服务器。

为Ubuntu,Debian,Kali,Mint安装MySQL / MariaDB客户端 (Install MySQL/MariaDB Client For Ubuntu, Debian, Kali, Mint)

We will start by installing MySQL/MariaDB command line client in the deb based distributions like Ubuntu, Debian, Kali, Mint etc. The package is named as mysql-client which we will install with the apt command like below.

我们将从在基于deb的发行版(如Ubuntu,Debian,Kali,Mint等)中安装MySQL / MariaDB命令行客户端开始。该软件包名为mysql-client ,将使用以下apt命令进行安装。

$ sudo apt install mysql-client

067c3c45832d4cd7c1409bd833a60c0c.png

Install MySQL/MariaDB Client For Ubuntu, Debian, Kali, Mint

为Ubuntu,Debian,Kali,Mint安装MySQL / MariaDB客户端

为Fedora,CentOS,RedHat安装MySQL / MariaDB客户端(Install MySQL/MariaDB Client For Fedora, CentOS, RedHat)

In the rpm based distributions like Fedora, CentOS, RedHat can be installed with the yum command like below. Also alternatively dnf can be used like below.

在Fedora,CentOS等基于rpm的发行版中,可以使用yum命令安装RedHat,如下所示。 另外,也可以像下面这样使用dnf。

$ sudo dnf install community-mysql

OR

要么

$ sudo yum install community-mysql

bcb492946dc7fe603561da73929ed3ea.png

Install MySQL/MariaDB Client For Fedora, CentOS, RedHat

为Fedora,CentOS,RedHat安装MySQL / MariaDB客户端

从命令行连接MySQL / MariaDB数据库(Connect MySQL/MariaDB Database From Command Line)

If MySQL/MariaDB database is installed on the local system we can use mysql tool to connect. We can use mysql command with the sudo command for Linux systems like Ubuntu, Debian, Fedora, Mint, CentOS etc.

如果在本地系统上安装了MySQL / MariaDB数据库,我们可以使用mysql工具进行连接。 对于Linux系统(例如Ubuntu,Debian,Fedora,Mint,CentOS等),我们可以将mysql命令与sudo命令一起使用。

$ sudo mysql

OR for Windows

或Windows

> mysql

1e51ed5fc34de80ada77b30dbd2dfca5.png

Connect MySQL/MariaDB Database From Command Line

从命令行连接MySQL / MariaDB数据库

从命令行连接指定用户名MySQL / MariaDB数据库(Connect Specifying Username MySQL/MariaDB Database From Command Line)

Default behavior of the mysql command is using the current user name. We can provide the user name explicitly with the -u option and the user name. In this example, we will connect with the user name root

mysql命令的默认行为是使用当前用户名。 我们可以使用-u选项和用户名显式地提供用户名。 在此示例中,我们将使用用户名root连接

$ sudo mysql -u root

45429d8605841578682951ef13a1ca87.png

Connect Specifying Username MySQL/MariaDB Database From Command Line

从命令行连接指定用户名MySQL / MariaDB数据库

通过命令行连接指定用户名和密码MySQL / MariaDB数据库(Connect Specifying Username and Password MySQL/MariaDB Database From Command Line)

Up to now, we have connected to the local MySQL/MariaDB database server without explicitly specifying the password. If we want to connect a remote database server we have to specify the password for the given user. We can also specify the remote server hostname or IP address with the -h option like below.

到目前为止,我们已经连接到本地MySQL / MariaDB数据库服务器,而没有显式指定密码。 如果要连接远程数据库服务器,则必须指定给定用户的密码。 我们还可以使用-h选项指定远程服务器的主机名或IP地址,如下所示。

$ mysql -u root -h 192.168.142.144

在不连接远程MySQL / MariaDB数据库的情况下运行SQL (Run SQL Without Connecting Remote MySQL/MariaDB Database)

mysql command provides different features like running SQL statements remotely without using the mysql shell. We can run the sql clause with the -e option like below.

mysql命令提供了不同的功能,例如无需使用mysql shell即可远程运行SQL语句。 我们可以使用-e选项运行sql子句,如下所示。

$ sudo mysql -u root -e "SELECT VERSION();"

5c6892350cbed2cdbc475c56fc9aebed.png

Run SQL Without Connecting Remote MySQL/MariaDB Database

在不连接远程MySQL / MariaDB数据库的情况下运行SQL

从命令行显示数据库 (Show Databases From Command Line)

If we want to list databases stored on the MySQL/MariaDB database without connecting them explicitly and using mysql shell we can use show databases; command like below.

如果我们要列出存储在MySQL / MariaDB数据库中的数据库而不用显式连接它们并使用mysql shell,则可以使用show databases; 命令如下。

$ sudo mysql -u root -e "show databases"

LEARN MORE  How To Use Mysql / MariaDB From Console?

了解更多如何从控制台使用Mysql / MariaDB?

b832943ab1bfdf4f65078f1d5fa63302.png

Run SQL Without Connecting Remote MySQL/MariaDB Database

在不连接远程MySQL / MariaDB数据库的情况下运行SQL

从命令行指定默认数据库 (Specify The Default Database From Command Line)

As we use command line tool mysql to connect and manage MySQL/MariaDB databases we need to specify the default database name in order to run SQL queries. We will use use statement with the database name in order to specify the default database the SQL queries run.

当我们使用命令行工具mysql连接和管理MySQL / MariaDB数据库时,我们需要指定默认数据库名称才能运行SQL查询。 我们将使用带有数据库名称的use语句,以指定SQL查询运行的默认数据库。

$ sudo mysql -u root -e "use sys;show tables;"

a9ede0b3e93d741f7a4a49cd5a79a6f1.png

How To Connect MySQL/MariaDB Server From Command Line On Linux and Windows?

如何在Linux和Windows上从命令行连接MySQL / MariaDB服务器?

从远程MySQL / MariaDB数据库服务器上的命令行运行SQL脚本或SQL文件 (Run SQL Script or SQL File From Command Line On Remote MySQL/MariaDB Database Server)

SQL scripts and statements can be stored in the SQL script file. We can run this script files without copy and paste just providing the file and redirecting the content of the file. We have the following SQL file content which is sqlscript.sql .

SQL脚本和语句可以存储在SQL脚本文件中。 我们可以仅提供文件并重定向文件内容而无需复制和粘贴来运行该脚本文件。 我们具有以下SQL文件内容sqlscript.sql。

select version();

show databases;

use sys;

select * from host_summary;

We have to also specify the database name as the last parameter to the mysql command which is sys in this case.

我们还必须指定数据库名称作为mysql命令的最后一个参数,在本例中为sys 。

$ sudo mysql -u root sys < sqlscript.sql

e1e1eeac402786b6b607143d4a6389ac.png

Run SQL Script or SQL File From Command Line On Remote MySQL/MariaDB Database Server

从远程MySQL / MariaDB数据库服务器上的命令行运行SQL脚本或SQL文件

翻译自: https://www.poftut.com/how-to-connect-mysql-mariadb-server-from-command-line-on-linux-and-windows/

如何在Linux和Windows上从命令行连接MySQL / MariaDB服务器?相关教程

如何在Linux上安装Wine Emulator并运行Windows应用程序?

如何在Linux上安装Wine Emulator并运行Windows应用程序? Linux is a very flexible operating system which provides different options for other operating system applications users. Wine is a tool used to run Windows operating system applications

bcdedit删除引导_Bcdedit命令教程以及用于编辑Windows引导配置的

bcdedit删除引导_Bcdedit命令教程以及用于编辑Windows引导配置的示例 bcdedit删除引导 bcdedit is a command line tool used to manage Boot Configuration Data (BCD). This tool can be used to store boot configuration, boot applications and related s

cmd命令和dos命令_在Windows MS-DOS命令行教程中,带有示例的CMD

cmd命令和dos命令_在Windows MS-DOS命令行教程中,带有示例的CMD / C是什么意思? cmd命令和dos命令 MS-DOS is an operating system and shell used to run commands and provide a command-line interface in Windows operating systems. cmd.exe is used to

ubuntu 安装kali_如何在Linux,Windows,Kali,Ubuntu,Mint和示

ubuntu 安装kali_如何在Linux,Windows,Kali,Ubuntu,Mint和示例中安装和使用exiftool ubuntu 安装kali exiftool is a platform independent command line and GUI application for reading, writing and editing meta information of images and media fil

WindowServer2012R2+Anoconda3.5.0.1+CUDA9.0+cuDNN7.1.3+Tensor

WindowServer2012R2+Anoconda3.5.0.1+CUDA9.0+cuDNN7.1.3+Tensorflow-gpu1.6离线搭建深度学习开发环境 WindowServer2012R2+Anoconda3.5.0.1+CUDA9.0+cuDNN7.1.3+Tensorflow-gpu1.6离线搭建深度学习开发环境 关键词 : Windows,Tensorflow-gpu,离线搭建 实验

Linux配置手册(七)安装并管理MySQL数据库

Linux配置手册(七)安装并管理MySQL数据库 基于DNS服务器与httpd服务搭建 安装MySQL 1. 创建运行MySQL数据库的系统用户,足 a) 2. 解压并释放源码包,并切换至展开的源码包目录 a) b) 3. 进行编译前配置 a) 4. 编译并安装 a) 5. 建立配置文件 a) 其中包括中

Linux配置手册(五)Linux 配置域名服务器(DNS)

Linux配置手册(五)Linux 配置域名服务器(DNS) 构建缓存域名服务器 检查域名服务包 挂在光盘并安装服务包 需要安装 bind-9.3.6-4.P1.el5 Bind-chroot-9.3.6-4.P1.el5 Bind-libs-9.3.6-4.P1.el5 Bind-utils-9.3.6-4.P1.el5 Caching-nameserver-9.3.6-4.P1.

给你一个选择windows server 2008的理由(工具篇)

给你一个选择windows server 2008的理由(工具篇) 当windows server 2008进入运用中,我们一直在讨论关于2008的性能问题,在我看来,windows server 2008所更新出的工具也是值得一提的。这些管理工具充分具备人性化和交互式管理的特点。让网络管理人员更轻

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值