mysql -h 127.0.0.1 -u root -P 3306 -p
-h: 指定 IP 地址
-u: 指定用户
-P: 指定端口(这个是大写的 P)
-p: 指定要输入密码,这个后面不需要跟参数
mysql> use information_schema;
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 database();
+--------------------+
| database() |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.7.27-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0.01 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2019-09-27 10:19:47 |
+---------------------+
1 row in set (0.00 sec)
mysql> select CURRENT_DATE;
+--------------+
| CURRENT_DATE |
+--------------+
| 2019-09-27 |
+--------------+
1 row in set (0.00 sec)
mysql> select YEAR(CURRENT_DATE);
+--------------------+
| YEAR(CURRENT_DATE) |
+--------------------+
| 2019 |
+--------------------+
1 row in set (0.00 sec)
mysql> select MONTH(CURRENT_DATE);
+---------------------+
| MONTH(CURRENT_DATE) |
+---------------------+
| 9 |
+---------------------+
1 row in set (0.00 sec)
mysql> select DAYOFMONTH(CURRENT_DATE);
+--------------------------+
| DAYOFMONTH(CURRENT_DATE) |
+--------------------------+
| 27 |
+--------------------------+
1 row in set (0.00 sec)