连接MySQL

本文介绍了MySQL数据库的基本操作,包括连接数据库管理系统、查看所有数据库、选择数据库、查看数据库中的所有表、查看表列定义以及退出登录等内容,为操作MySQL数据库提供了基础指引。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

连接数据库管理系统

baozi@ubuntu:~$ mysql -u root -p
Enter password: 

查看数据库管理系统中的所有数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

选择数据库

就像编辑Excel要先选中文件一样,操作数据库也要先选择一个数据库

mysql> use mysql;
Database changed

查看数据库中的所有表

mysql> show tables;
+----------------------------------------------+
| Tables_in_mysql                              |
+----------------------------------------------+
| columns_priv                                 |
| component                                    |
| db                                           |
| default_roles                                |
| engine_cost                                  |
| func                                         |
| general_log                                  |
| global_grants                                |
| gtid_executed                                |
| help_category                                |
| help_keyword                                 |
| help_relation                                |
| help_topic                                   |
| innodb_index_stats                           |
| innodb_table_stats                           |
| password_history                             |
| plugin                                       |
| procs_priv                                   |
| proxies_priv                                 |
| replication_asynchronous_connection_failover |
| role_edges                                   |
| server_cost                                  |
| servers                                      |
| slave_master_info                            |
| slave_relay_log_info                         |
| slave_worker_info                            |
| slow_log                                     |
| tables_priv                                  |
| time_zone                                    |
| time_zone_leap_second                        |
| time_zone_name                               |
| time_zone_transition                         |
| time_zone_transition_type                    |
| user                                         |
+----------------------------------------------+
34 rows in set (0.00 sec)

查看表中每一列的定义

mysql> show columns from component;
+--------------------+--------------+------+-----+---------+----------------+
| Field              | Type         | Null | Key | Default | Extra          |
+--------------------+--------------+------+-----+---------+----------------+
| component_id       | int unsigned | NO   | PRI | NULL    | auto_increment |
| component_group_id | int unsigned | NO   |     | NULL    |                |
| component_urn      | text         | NO   |     | NULL    |                |
+--------------------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

退出登录

mysql> \q
Bye
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值