MySQL数据库安装参考:https://blog.csdn.net/u010637291/article/details/112101269
1. 启动数据库 mysql -u root -p
以管理员身份打开 cmd 命令行工具,切换目录;
# 以管理员权限打开cmd命令行工具
cd E:\Program\MySQL\mysql-8.0.22-winx64\bin
# 注:由于命令行没有跳转到相应目录,此时我再输入e: 才跳转。通常情况下不需输入e:
如果我们要登录本机的 MySQL 数据库,只需要输入以下命令即可:
mysql -u root -p
按回车确认, 如果安装正确且 MySQL 正在运行, 会得到以下响应:
Enter password:
若密码存在, 输入密码登录, 不存在则直接按回车登录。登录成功后你将会看到 Welcome to the MySQL monitor...
的提示语:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22
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.
然后命令提示符会一直以 mysq> 加一个闪烁的光标等待命令的输入, 输入 exit
或 quit
可退出登录。
2. 数据库创建、查看、删除
2.1 数据库查看 show databases
show databases;
2.2 选择数据库 select database() mydb
select database() mydb;
2.3 删除数据库 drop database mydb
drop database mydb;
# 可再进行查看数据库
show databases;
2.4 创建数据库 create database mydb
create database caas_database;
或
create database caas_database default character set utf8;
2.4 使用数据库 use mydb
use caas_database;
执行以上命令后,你就已经成功选择了 caas_database`数据库,在后续的操作中都会在 caas_database数据库中执行。
3. 数据表创建、查看、删除、修改
3.1 创建数据表 create table mytable
(…)
在选择当前数据库后,可进行创建数据表:
/*
Navicat MySQL Data Transfer
Source Server : 81.70.165.134
Source Server Version : 50717
Source Host : 81.70.165.134:3306
Source Database : patentanalysis
Target Server Type : MYSQL
Target Server Version : 50717
File Encoding : 65001
Date: 2021-02-23 07:37:58
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for su_patent
-- ----------------------------
DROP TABLE IF EXISTS `su_patent`;
CREATE TABLE `su_patent` (
`patent_id` int