MYSQL从前到后

夜深人静的时候总是想爬起来写点啥!


又想写写mysql的种种,就从安装到SQL语句吧!

  • 安装MySQL参考这是常有的事

  • 连接MySQL数据

mysql -h localhost -u root -p
然后输入密码连接,连接成功后是这样
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.6.25 MySQL Community Server (GPL)
mysql> 等待输入指令

  • 数据库的定义语句,常用指令
  1. 创建数据库

create database demodb;
Query OK, 1 row affected (0.00 sec) 显示这样表示执行成功

  1. 查看数据库

show databases;

  1. 选中数据库

use demodb;

  1. 查看当前使用库有哪些表

show tables;

  1. 删除数据库

drop database demodb;

  • 数据表操作, 常用指令
  1. 创建表

create table tb_demo(
tbname varchar(10),
tbdate date,
tbsal float(10,2),
tbno int(2)
);

  1. 查看表字段结构

desc tb_demo;

  1. 查看表创建语句

show create table tb_demo G;

  1. 删除表

drop table tb_demo;

原文地址:https://www.cnblogs.com/yymor/p/11456715.html