Skip to content

Instantly share code, notes, and snippets.

@CoXier
Last active November 4, 2019 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoXier/49c04a2d31bd99e130a00c8398659e70 to your computer and use it in GitHub Desktop.
Save CoXier/49c04a2d31bd99e130a00c8398659e70 to your computer and use it in GitHub Desktop.

一、MySQL 安装

创建用户:https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql mysql 常用操作:https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial#how-to-access-a-mysql-database

推荐一个好用的终端 mysql 工具:https://github.com/dbcli/mycli ,mycli 比起原生 mysql 终端增加了补全和高亮功能。

查看当前数据库或者表的 create 语句:

show create table table_name
show create database database_name

二、SQL 常用句型

  • 创建 database
CREATE DATABASE databse_name;
  • 使用 database
USE database_name;
  • 创建表
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
  • 修改表结构
alter table table_name Change `TimeStamp` `time_stamp` float not null
  • 添加字段
 alter table table_name ADD column new_column type

三、 在 Python 中使用 MySQL

现在 package mysql-connector 支持在 Python 中操作数据库。文档:https://dev.mysql.com/doc/connector-python/en/connector-python-examples.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment