在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中的所有表?
答案 0 :(得分:2)
使用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)
如何在数据库中看到mysql中的所有表?
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)
答案 1 :(得分:1)
使用man mysql
查看mysql联机帮助页,您将找到-D
标记:
· --database=db_name, -D db_name The database to use. This is useful primarily in an option file.
答案 2 :(得分:1)
其他答案提及--database
/ -D
选项,但您甚至不需要。
https://dev.mysql.com/doc/refman/5.7/en/mysql.html显示了更简单的示例:
使用mysql非常简单。从命令提示符调用它 翻译如下:
shell> mysql db_name
换句话说,与您为postgres <database_name>
显示的用法完全一样。
您可能还需要提供用户名和密码来验证MySQL实例,但我更喜欢将它们放入选项文件中,因此我不必重复输入它们。
$ cat ~/.my.cnf
[client]
username = scott
password = tiger
有关这些文件的详情,请参阅https://dev.mysql.com/doc/refman/5.7/en/option-files.html。
还有一种可选的方法来存储加密的用户凭据。对于此https://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.html
如果您尝试阅读一些文档,任何软件都更容易使用! : - )