gpt4 book ai didi

mysql - 访问 mysql 数据库表的更简单方法?

转载 作者:行者123 更新时间:2023-11-29 04:34:31 24 4
gpt4 key购买 nike

postgresql您需要做的就是输入 postgres <database_name>访问数据库。在 MySql 中,你需要这样做:

mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 52
Server version: 5.7.20 Homebrew

Copyright (c) 2000, 2017, 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> use arthouse_development
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from catalog_items;
Empty set (0.00 sec)

mysql> select * from catalog_items
-> ;
Empty set (0.00 sec)

mysql> select * from users;
Empty set (0.01 sec)

mysql> select * from users
-> ;
Empty set (0.00 sec)

有没有办法不必在一行中指定用户名和指定数据库?

一旦进入数据库,如何查看 mysql 中的所有表?

最佳答案

使用程序mysql的-D选项默认登录数据库。
-p 选项让你在 mysql 程序中输入密码

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -u root -p -D stackoverflow
Enter password: **
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

确认我们正在使用数据库 stackoverflow。

mysql> select database();
+---------------+
| database() |
+---------------+
| stackoverflow |
+---------------+
1 row in set (0.00 sec)

How do you see all the tables in mysql once inside the database?

mysql> show tables;
+-------------------------+
| Tables_in_stackoverflow |
+-------------------------+
| baskets |
| baskets_fruits |
| conditions |
| employee |
| employees |
| hugetable |
| kanji |
| newtable |
| result |
| t1 |
| t2 |
| table1 |
| table_test |
| temp |
| test |
| testing |
| word |
+-------------------------+
17 rows in set (0.00 sec)

或者通过使用 information_schema.TABLES 表

mysql> SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'stackoverflow';
+----------------+
| TABLE_NAME |
+----------------+
| baskets |
| baskets_fruits |
| conditions |
| employee |
| employees |
| hugetable |
| kanji |
| newtable |
| result |
| t1 |
| t2 |
| table1 |
| table_test |
| temp |
| test |
| testing |
| word |
+----------------+
17 rows in set (0.00 sec)

关于mysql - 访问 mysql 数据库表的更简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47081194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com