-
打开终端。
-
连接到 MySQL 服务器(假设你的mysql叫root):
mysql -u root -p
-
输入密码:
Enter password: ********
-
查看所有数据库:
mysql> SHOW DATABASES;
ERROR 4031 (HY000): The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.
No connection. Trying to reconnect...
Connection id: 87
Current database: eladmin
+--------------------+
| Database |
+--------------------+
| blog_system |
| blog_test |
| eladmin |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
7 rows in set (0.06 sec)
这样,你就可以查看当前 MySQL 服务器上所有的数据库了。
5.选择某个数据库:
use xxx;
mysql> use eladmin;
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>
这样,你就可以选择并使用指定的数据库了。选择数据库后,你可以执行针对该数据库的 SQL 查询和其他操作。
查看该数据库中的所有表:
SHOW TABLES;
这将显示数据库中的所有表。例如:
mysql> show tables;
+--------------------+
| Tables_in_eladmin |
+--------------------+
| code_column_config |
| code_gen_config |
| mnt_app |
| mnt_database |
| mnt_deploy |
| mnt_deploy_history |
| mnt_deploy_server |
| mnt_server |
| sys_dept |
| sys_dict |
| sys_dict_detail |
| sys_job |
| sys_log |
| sys_menu |
| sys_quartz_job |
| sys_quartz_log |
| sys_role |
| sys_roles_depts |
| sys_roles_menus |
| sys_user |
| sys_users_jobs |
| sys_users_roles |
| tool_alipay_config |
| tool_email_config |
| tool_local_storage |
| tool_qiniu_config |
| tool_qiniu_content |
+--------------------+
27 rows in set (0.00 sec)
6、查询数据库表的所有内容:
SELECT * FROM sys_user;