3. 连接 MySQL 服务

下面我们使用 mysql 的客户端软件连接 MySQL 服务器。

首先下载并安装 MySQL 的客户端软件 mysql-client,命令如下:

sudo apt install mysql-client

使用如下命令连接 MySQL 服务器:

mysql -h 127.0.0.1 -u root -p

执行结果

weimingze@mzstudio:~$ mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 9.3.0 MySQL Community Server - GPL

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> quit;
Bye

以上 MySQL 的 root 密码是 weimingze.com

在 MySQL 客户端内使用 show databases; 可以查看内部的数据库,说明 数据库安装成功。

至此,MySQL数据库安装结束。