mysql的登陆和退出命令格式

时间:2022-10-28 18:01:49

mysql登陆的命令格式为:

?
1
mysql -h [hostip] -u [username] -p [password] [database]

1.普通登陆mysql数据库
命令格式:mysql -u 用户名 -p 密码,例如: mysql -u root -p root
如果在-p后没有提供密码,则会在执行命令后要求用户输入密码

mysql的登陆和退出命令格式

2.制定端口号登陆,mysql的默认端口号是3306,
命令格式:mysql -u 用户名 -p 密码 -p 端口号
即可,注意指定端口的字母p为大写,而标识密码的p为小写。

mysql的登陆和退出命令格式

3.指定ip地址和端口号登录mysql数据库
命令格式为:mysql -h ip -u 用户 -p -p 端口号
例如:mysql -h 127.0.0.1 -u root -p -p 3306

mysql的登陆和退出命令格式
mysql的登陆和退出命令格式

4.制定数据库登陆
mysql -h ip地址 -u 用户名 -p 密码 数据库名
例如:mysql -h 127.0.0.1 -u root -p test

查看当前登陆用户和数据库

mysql的登陆和退出命令格式

?
1
2
select user();
  select database();

退出登陆命令
登陆进入mysql进入之后,可能到下面的提示信息,可以help看看输出结果

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mysql> help
 
for information about mysql products and services, visit:
  http://www.mysql.com/
for developer information, including the mysql reference manual, visit:
  http://dev.mysql.com/
to buy mysql enterprise support, training, or other products, visit:
  https://shop.mysql.com/
 
list of all mysql commands:
note that all text commands must be first on line and end with ';'
?     (\?) synonym for `help'.
clear   (\c) clear the current input statement.
connect  (\r) reconnect to the server. optional arguments are db and host.
delimiter (\d) set statement delimiter.
edit   (\e) edit command with $editor.
ego    (\g) send command to mysql server, display result vertically.
exit   (\q) exit mysql. same as quit.
go    (\g) send command to mysql server.
help   (\h) display this help.
nopager  (\n) disable pager, print to stdout.
notee   (\t) don't write into outfile.
pager   (\p) set pager [to_pager]. print the query results via pager.
print   (\p) print current command.
prompt  (\r) change your mysql prompt.
quit   (\q) quit mysql.
rehash  (\#) rebuild completion hash.
source  (\.) execute an sql script file. takes a file name as an argument.
status  (\s) get status information from the server.
system  (\!) execute a system shell command.
tee    (\t) set outfile [to_outfile]. append everything into given outfile.
use    (\u) use another database. takes database name as argument.
charset  (\c) switch to another charset. might be needed for processing binlog with multi-byte charsets.
warnings (\w) show warnings after every statement.
nowarning (\w) don't show warnings after every statement.
resetconnection(\x) clean session context.
 
for server side help, type 'help contents'

通过输出信息,我们知道如下三条退出mysql的命令
1. exit
2. quit
3. \q

到此这篇关于mysql的登陆和退出命令格式的文章就介绍到这了,更多相关mysql登陆和退出内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_36744627/article/details/81144005