命令行连接数据库

命令行连接数据库

命令行连接

注意一定要加;号

-- 单行注释(SQL的本来的注释)
/*  (SQL的多行注释)
1234
12345
1234
*/
1. mysql -uroot -p123456-- 连接数据库
   update mysql.user set authentication_string=password('678453') where user='root' and Host =
2.'localhost';-- 修改用户密码
3. flush privileges;-- 刷新数据
-- 所有的语句都使用;结尾
4. show databases;-- 查看所有的数据库
5. mysql> use school;-- 切换数据库(use 数据库名)
   Database changed
6. show tables;-- 查看数据库中所有的表
7. describe students;-- 显示数据库中所有的表的信息
8. create database westos;-- 创建一个数据库
9. exit;-- 退出连接
C:\Windows\system32>mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> show databases;                
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| person             |
| school             |
| sys                |
| teacher            |
| westos             |
+--------------------+
8 rows in set (0.00 sec)

mysql> use school;
Database changed
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| student          |
+------------------+
1 row in set (0.00 sec)

mysql> describe students;
ERROR 1146 (42S02): Table 'school.students' doesn't exist
mysql> describe student
    -> ;
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(4)       | NO   | PRI | NULL    | auto_increment |
| name     | varchar(30)  | NO   |     ||                |
| sex      | varchar(2)   | NO   |     ||                |
| birthday | datetime     | YES  |     | NULL    |                |
| address  | varchar(100) | YES  |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> exit;
Bye

C:\Windows\system32>

(参考狂神说的视频,加上自己的理解总结了这篇文章)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值