命令行连接数据库
命令行连接
注意一定要加;号
-- 单行注释(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>
(参考狂神说的视频,加上自己的理解总结了这篇文章)