码迷,mamicode.com
首页 > 数据库 > 详细

Xshell怎么连接数据库

时间:2021-06-10 18:40:18      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:name   rgb   span   shell   方案   from   password   div   can   

一,打开xshell,连接上

输入指令:mysql -h 192.168.10.120 -u root -p 回车,-h后面是数据库hostname,-u后面是数据库用户名,-p后面是密码

 1 root@VM-0-12-centos[14:05:47]:~
 2 $ mysql -h ** -u ** -p
 3 Enter password: 
 4 Welcome to the MySQL monitor.  Commands end with ; or \g.
 5 Your MySQL connection id is 52674
 6 Server version: 5.6.25 Source distribution
 7 
 8 Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
 9 
10 Oracle is a registered trademark of Oracle Corporation and/or its
11 affiliates. Other names may be trademarks of their respective
12 owners.
13 
14 Type help; or \h for help. Type \c to clear the current input statement.
15 
16 mysql>

这样就表示连接上了。里面输入SQL语句就和MySQL一样使用,注意SQL语句的结尾分号“;”必须有!,否则会报错。

 1 #查看数据库
 2 mysql> show databases;
 3 +--------------------+
 4 | Database           |
 5 +--------------------+
 6 | n_schema |
 7 | ao_students |
 8 | students |
 9 | aoshi          |
10 | test_ab            |
11 +--------------------+
12 5 rows in set (0.02 sec)

查看数据表:

 1 mysql> use test_ab;
 2 Reading table information for completion of table and column names
 3 You can turn off this feature to get a quicker startup with -A
 4 
 5 Database changed
 6 mysql> show tables;
 7 +-------------------+
 8 | Tables_in_test_ab |
 9 +-------------------+
10 | mytb1             |
11 | tb                |
12 | tb_emp1           |
13 | tb_emp2           |
14 | tg                |
15 | tt                |
16 | tt1               |
17 | ty                |
18 +-------------------+
19 8 rows in set (0.03 sec)

 表格查询:

 1 mysql> select * from ty;
 2 +----+--------------+--------+-------+
 3 | id | nam          | deptid | slary |
 4 +----+--------------+--------+-------+
 5 |  1 | 嗯嗯呃呃 |      1 | 20000 |
 6 |  2 |              |      2 | 33434 |
 7 |  3 | 嗯嗯       |      1 | 20000 |
 8 |  4 | 开          |      2 | 33434 |
 9 |  5 | erew         |      1 | 20000 |
10 |  6 |              |      2 | 33434 |
11 |  7 |              |      5 | 25000 |
12 |  8 | 张三       |      1 | 20000 |
13 |  9 | 李四       |      2 | 33434 |
14 | 10 | 王五       |      1 | 20000 |
15 | 11 | 人          |      2 | 33434 |
16 | 12 | 有          |      1 | 20000 |
17 | 13 |              |      5 | 25000 |
18 | 14 | 张三       |      3 |  1984 |
19 | 15 | 李四       |     45 |  1982 |
20 | 16 | 王五       |     76 |  1982 |
21 | 17 | 人          |     48 |  1988 |
22 | 18 | 有          |     90 |  1928 |
23 | 19 |              |     23 |  1988 |
24 +----+--------------+--------+-------+
25 19 rows in set (0.03 sec)

出现中文乱码问题,可以用以下命令临时解决,为什么是临时解决?重新登入后还是有有乱码问题。表格没有对齐—现在各大网站还没有更好的解决方案。

1 mysql> set names utf8;
2 Query OK, 0 rows affected (0.03 sec)

今天先寄这些,后面再更。

 

Xshell怎么连接数据库

标签:name   rgb   span   shell   方案   from   password   div   can   

原文地址:https://www.cnblogs.com/kongguyoulan/p/14871072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!