01.MySQL命令行基本操作

2018-12-20  本文已影响32人  Liuzhl

开启/停止MySQL服务

PS C:\WINDOWS\system32> net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。

PS C:\WINDOWS\system32> net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。

登陆和退出MySQL

参数 说明
-V MySQL版本信息
-u 用户名
-p 密码
-P 端口号 如果没改过,那么就是3306,可以不写
-h 服务器名称,如果是本机,那么就是127.0.0.1,可以不写
PS C:\WINDOWS\system32> mysql -V
C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe  Ver 14.14 Distrib 5.5.40, for Win64 (x86)
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> mysql -uroot -p -P3306 -hlocalhost
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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>

修改提示符

PS C:\WINDOWS\system32> mysql -uroot -proot --prompt \h@\D>

localhost@Wed May 09 10:17:35 2018>
localhost@Wed May 09 10:18:35 2018>
mysql> prompt \u-\h-\D-\d>
PROMPT set to '\u-\h-\D-\d>'
root-localhost-Wed May 09 10:23:39 2018-(none)>use test
Database changed
root-localhost-Wed May 09 10:24:02 2018-test>
参数 说明
\u 用户名
\h 服务器地址
\D 时间
\d 数据库名

MySQL常用命令以及语句规范

语句规范

mysql> prompt mysql-\d>
PROMPT set to 'mysql-\d>'
mysql-(none)>SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.5.40    |
+-----------+
1 row in set (0.00 sec)

mysql-(none)>SELECT NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2018-05-09 10:34:39 |
+---------------------+
1 row in set (0.00 sec)

mysql-(none)>SELECT USER();
+----------------+
| USER()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql-(none)>select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql-(none)>


上一篇下一篇

猜你喜欢

热点阅读