怎么登陆和退出MySQL

1.使用管理员身份进入命令提示符(cmd),进入%MySQL_HOME%\bin 目录下,

MySQL_HOME为自己的安装路径。

2. 启动mysql数据库 。DOS命令窗口中输入 net start mysql, 
Shell> net start mysql
3.登陆数据库。 
方式一:
shell> mysql -h host -u user -p
Enter password: ********
host并 user表示运行MySQL服务器的主机名和MySQL帐户的用户名。替换适合您的设置的值。该 ********代表你的密码; 
mysql显示Enter password:提示时输入它
例子如:
shell>mysql -h localhost -u root -p
Enter password: *********
localhost:表示本地;-u为数据库用户名,root是mysql默认用户名;-p为密码,
       1)如果设置了密码,可直接在-p后链接输入,如:-p666;
2)用户没有设置密码,显示Enter password时,直接回车即可。
例如:mysql -hlocalhost -uroot -p666回车直接登陆

方式二:

 如果你在运行MySQL的同一台计算机上登录,则可以省略主机,只需使用以下命令:

shell> mysql -u user -p
如:
E:\MySQL\mysql-5.7.21-winx64\bin>mysql -u root -p
Enter password: *********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.21 MySQL Community Server (GPL)

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

4.可以输入show databases;查看下数据库;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| boot_crm           |
| crm                |
| music              |
| mysql              |
| performance_schema |
| springmvc          |
+--------------------+
7 rows in set (0.00 sec)
5.成功连接后,QUIT(或\q)【不区分大小写】来随时断开连接mysql>
mysql> quit
6.关闭数据库命令为net stop mysql


版权声明:本文为Butterfly_resting原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。