Linux安装MySQL怎么连接
时间: 2025-02-07 11:58:23 浏览: 27
### 连接到MySQL数据库
安装完成后,可以通过命令行工具 `mysql` 来连接到本地或远程的 MySQL 数据库服务器。对于初次配置来说,在本机上验证安装是否成功通常是最简单的做法。
#### 使用命令行客户端登录
输入如下命令来启动 MySQL 客户端并尝试登陆:
```bash
$ mysql -u root -p` 参数则指示程序等待用户提供密码。
如果之前设置了root用户的密码,则需要在此处键入该密码以完成认证过程。一旦通过验证,将会进入 MySQL 的交互界面,显示类似于下面的信息:
```plaintext
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, 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 '\h' for help. Type '\c' to clear the current input statement.
mysql>
```
此时即表示已经成功建立了与 MySQL 数据库之间的连接[^3]。
为了进一步确认服务状态良好运行以及版本信息无误,可以执行以下 SQL 查询语句获取当前使用的 MySQL 版本号:
```sql
SELECT VERSION();
```
这将返回一行数据,其中包含了所部署的具体 MySQL 发行版及其构建平台详情。
阅读全文
相关推荐

















