每日MySQL之002:MySQL server连接与查询
2017-08-01 21:50
381 查看
1 连接到 MySQL server
mysql命令是一个client MySQL Command-Line Tool 工具,它可以用来连接MySQL server,连接成功之后,会提供一个交互shell, 最常见的语法如下:
shell> mysql -h host -u user -p
其中-h 表示hostname, -u表示用户名,-p表示要输入密码:
db2a:~ # mysql -h localhost -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.19 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.
mysql>
2 开始查询
查询当前版本和日期,最后要以';'结尾:
mysql> select version(), current_date;
+-----------+--------------+
| version() | current_date |
+-----------+--------------+
| 5.7.19 | 2017-07-24 |
+-----------+--------------+
1 row in set (0.00 sec)
select语句不区分大小写;
mysql> SeLeCt vErSiOn(), current_DATE;
+-----------+--------------+
| vErSiOn() | current_DATE |
+-----------+--------------+
| 5.7.19 | 2017-07-24 |
+-----------+--------------+
1 row in set (0.00 sec)
可以作为简单的计算器:
mysql> select PI(),sin(PI()/4), (4+1)*5;
+----------+--------------------+---------+
| PI() | sin(PI()/4) | (4+1)*5 |
+----------+--------------------+---------+
| 3.141593 | 0.7071067811865475 | 25 |
+----------+--------------------+---------+
1 row in set (0.01 sec)
可以一行放两条SQL:
mysql> select version();select now();
+-----------+
| version() |
+-----------+
| 5.7.19 |
+-----------+
1 row in set (0.00 sec)
+---------------------+
| now() |
+---------------------+
| 2017-07-24 15:06:02 |
+---------------------+
1 row in set (0.00 sec)
一条SQL也可以分行输入:
mysql> select
-> user()
-> ,
-> current_date;
+----------------+--------------+
| user() | current_date |
+----------------+--------------+
| root@localhost | 2017-07-24 |
+----------------+--------------+
1 row in set (0.01 sec)
输入的过程中,如果想要取消,可以输入\c
mysql> select
-> user()
-> \c
mysql>
mysql命令是一个client MySQL Command-Line Tool 工具,它可以用来连接MySQL server,连接成功之后,会提供一个交互shell, 最常见的语法如下:
shell> mysql -h host -u user -p
其中-h 表示hostname, -u表示用户名,-p表示要输入密码:
db2a:~ # mysql -h localhost -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.19 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.
mysql>
2 开始查询
查询当前版本和日期,最后要以';'结尾:
mysql> select version(), current_date;
+-----------+--------------+
| version() | current_date |
+-----------+--------------+
| 5.7.19 | 2017-07-24 |
+-----------+--------------+
1 row in set (0.00 sec)
select语句不区分大小写;
mysql> SeLeCt vErSiOn(), current_DATE;
+-----------+--------------+
| vErSiOn() | current_DATE |
+-----------+--------------+
| 5.7.19 | 2017-07-24 |
+-----------+--------------+
1 row in set (0.00 sec)
可以作为简单的计算器:
mysql> select PI(),sin(PI()/4), (4+1)*5;
+----------+--------------------+---------+
| PI() | sin(PI()/4) | (4+1)*5 |
+----------+--------------------+---------+
| 3.141593 | 0.7071067811865475 | 25 |
+----------+--------------------+---------+
1 row in set (0.01 sec)
可以一行放两条SQL:
mysql> select version();select now();
+-----------+
| version() |
+-----------+
| 5.7.19 |
+-----------+
1 row in set (0.00 sec)
+---------------------+
| now() |
+---------------------+
| 2017-07-24 15:06:02 |
+---------------------+
1 row in set (0.00 sec)
一条SQL也可以分行输入:
mysql> select
-> user()
-> ,
-> current_date;
+----------------+--------------+
| user() | current_date |
+----------------+--------------+
| root@localhost | 2017-07-24 |
+----------------+--------------+
1 row in set (0.01 sec)
输入的过程中,如果想要取消,可以输入\c
mysql> select
-> user()
-> \c
mysql>
相关文章推荐
- mysql多表查询(二)内连接
- mysql 连接查询
- java web连接mysql异常Communication failure during handshake. Is there a server running on localhost
- MySQL学习笔记9:连接查询
- jdbc连接mysql时报message from server: "Host '**' is not allowed to connect to this MySQL server"错误解决
- Mysql 连接查询 Mysql支持的连接查询有哪些
- JAVA连接MYSQL,查询 ,添加,删除,语句
- 解决问题——SQLyog连接报错:Host ''xxx.xx.xxx.xxx'' is not allowed to connect to this MySQL server
- MySQL之多表查询--连接查询
- MYSQL 的重新连接错误:MySQL server has gone away
- Mysql 连接查询 Mysql支持的连接查询有哪些
- MySQL 子查询和连接
- 解决服务器连接错误Host ‘XXX’ is not allowed to connect to this MySQL server
- MySQL(3)-子查询、连接、运算符及函数
- 每日MySQL之016:MySQL Server客户端工具-mysqladmin
- navicate连接Linux下mysql慢,卡,以及mysql相关查询,授权
- mysql连接linux系统提示“登录出现1130 is not allowed to connect to this MySql server”问题,解决方法
- [mysql]子查询与连接
- MySQL 查询 -- 表连接
- 在刚启电脑时启动Navicat for MySql后连接mysql时报ERROR 2003 (HY000): Can't connect to MySQL server on 'localhos错误