最近打算重新学习一下mysql数据库,手上正好有一个树莓派,正好那它来练手。
在这里树莓派的连接工具是Xshell 5。
mysql数据库的连接工具是:Navicate Premium
这个界面是XShell的界面
Xshell 5 (Build 0964)
Copyright (c) 2002-2016 NetSarang Computer, Inc. All rights reserved.
Type `help' to learn how to use Xshell prompt.
[c:\~]$
这个是连接到树莓派之后的界面
Connecting to 192.168.1.103:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Nov 16 16:19:44 2016
pi@raspberrypi:~ $
1. 连接与断开服务器
登陆mysql,并查看mysql的版本
pi@raspberrypi:~ $ mysql -u zhang -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.5.52-0+deb8u1 (Raspbian)
Copyright (c) 2000, 2016, 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> select version();
+-----------------+
| version() |
+-----------------+
| 5.5.52-0+deb8u1 |
+-----------------+
1 row in set (0.00 sec)
mysql>
退出mysql数据库
mysql> quit
Bye
,
mysql> exit
Bye
或者是按 Ctrl+D
2. 输入查询
mysql> select version(),current_date;
+-----------------+--------------+
| version() | current_date |
+-----------------+--------------+
| 5.5.52-0+deb8u1 | 2016-11-19 |
+-----------------+--------------+
1 row in set (0.00 sec)
mysql> select version(),current_date,host,user();
ERROR 1054 (42S22): Unknown column 'host' in 'field list'
mysql> select version(),current_date,user();
+-----------------+--------------+-----------------+
| version() | current_date | user() |
+-----------------+--------------+-----------------+
| 5.5.52-0+deb8u1 | 2016-11-19 | zhang@localhost |
+-----------------+--------------+-----------------+
1 row in set (0.00 sec)
mysql> -- 如果你输入命令包含错误,可以用\c进行取消
mysql> select user()
-> \c
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> -- 创建并使用数据库
mysql> -- 查看当前服务器上已经存在的数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> -- 使用数据库
mysql> use test;
Database changed
mysql> -- 查看当前使用过的数据库
mysql> select database();
+------------+
| database() |
+------------+
| test |
+------------+
1 row in set (0.00 sec)
mysql> -- 创建并选择数据库
mysql> create database menagerie;
Query OK, 1 row affected (0.00 sec)
mysql> use menageries;
ERROR 1049 (42000): Unknown database 'menageries'
mysql> use menagerie;
Database changed
mysql> -- 也可以在连接数据库的时候指定数据库
mysql>