教你使用MySQL Shell连接数据库的方法

吾爱主题 阅读:122 2024-04-01 23:24:33 评论:0

在有些情况下我们需要使用命令行方式连接MySQL数据库,这时可以使用MySQL官方提供的命令行工具MySQL Shell

一、下载MySQL Shell

下载地址:https://dev.mysql.com/downloads/shell/

注意下载地址为下面的Other Downloads,上面的Recommended Download是MySQL数据库的下载地址。

二、配置运行环境

下载后得到一个名为mysql-shell-8.0.19-windows-x86-64bit.zip的压缩包,将该压缩包解压后执行其bin目录下的mysqlsh.exe程序即可,为了方便也可以直接将程序路径添加到环境变量Path中,如下图所示。

打开Windows PowerShell或CMD窗口,输入mysqlsh --version,如果出现版本提示则表明环境变量配置成功。

?
1 2 3 PS C:Userszhbao> mysqlsh --version D:Program FilesMySQLmysql-shell-8.0.19-windows-x86-64bitinmysqlsh.exe   Ver 8.0.19 for Win64 on x86_64 - for MySQL 8.0.19 (MySQL Community Server (GPL))

三、连接MySQL数据库

连接数据库的方法有两种,第一种是直接在命令行中输入mysqlsh命令和数据库地址等信息,然后根据提示输入密码即可。

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 PS C:Userszhbao> mysqlsh admin48@10.53.122.98:3360 Please provide the password for 'admin48@10.53.122.98:3360' : ****** Save password for 'admin48@10.53.122.98:3360' ? [Y]es/[N]o /Ne [ v ]er (default No): n MySQL Shell 8.0.19   Copyright (c) 2016, 2019, Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and /or its affiliates. Other names may be trademarks of their respective owners.   Type 'help' or '?' for help; 'quit' to exit . Creating a session to 'admin48@10.53.122.98:3360' Fetching schema names for autocompletion... Press ^C to stop. Your MySQL connection id is 958 Server version: 5.7.20 MySQL Community Server (GPL) No default schema selected; type use <schema> to set one.   MySQL  10.53.122.98:3360  JS >

另一种方法是先输入mysqlsh启动程序,然后再通过connect命令连接数据库。

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 PS C:Userszhbao> mysqlsh MySQL Shell 8.0.19   Copyright (c) 2016, 2019, Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and /or its affiliates. Other names may be trademarks of their respective owners.   Type 'help' or '?' for help; 'quit' to exit .   MySQL  JS > connect admin48@10.53.122.98:3360 Creating a session to 'admin48@10.53.122.98:3360' Please provide the password for 'admin48@10.53.122.98:3360' : ****** Save password for 'admin48@10.53.122.98:3360' ? [Y]es/[N]o /Ne [ v ]er (default No): n Fetching schema names for autocompletion... Press ^C to stop. Your MySQL connection id is 960 Server version: 5.7.20 MySQL Community Server (GPL) No default schema selected; type use <schema> to set one.   MySQL  10.53.122.98:3360  JS >

MySQL Shell默认是JS语言交互模式,可以通过sql命令切换到SQL语言交互模式。

?
1 2 3 MySQL  10.53.122.98:3360  JS > sql Switching to SQL mode... Commands end with ;   MySQL  10.53.122.98:3360  SQL >

接下来就可以通过SQL语言执行数据库命令了。

到此这篇关于使用MySQL Shell连接数据库的方法的文章就介绍到这了,更多相关MySQL Shell连接数据库内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/m0_67401606/article/details/124115350

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容