1.打开cmd,并进入msyql安装目录
比如我们的安装目录是:
C:\Program Files\MySQL\MySQL Server 5.7\bin
如果不进入安装目录,执行会报找不到mysql命令
2. 在DOS命令窗口输入 mysql -hlocalhost -uroot -p回车 进入mysql数据库
在DOS命令窗口输入 mysql -hlocalhost -uroot -p
回车 进入mysql数据库,其中-h
表示服务器名,localhost
表示本地;-u
为数据库用户名,root
是mysql默认用户名;-p
为密码,如果设置了密码,可直接在-p
后链接输入,如:-p123456
,用户没有设置密码,显示Enter password时,直接回车即可。
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -hlocalhost -uroot -p
`Enter password`: ******** //`提示输入密码`
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.17-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> //`此时可以输入命令了`
3. 查看所有数据库命令
输入show databases;显示你拥有的所有数据库
mysql数据库中的命令必须以分号结尾“
;
”
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
| yiibaidb |
+--------------------+
7 rows in set (0.00 sec)
mysql>
4. 使用某个数据库命令
mysql> use world;
Database changed
mysql>