Skip to content

Instantly share code, notes, and snippets.

@fengt
Last active January 23, 2018 08:49
Show Gist options
  • Save fengt/0284490d0d638cf48fbd1fa7799de521 to your computer and use it in GitHub Desktop.
Save fengt/0284490d0d638cf48fbd1fa7799de521 to your computer and use it in GitHub Desktop.
This is common operation of mysql table.
  • modify column type:
alter table formula_details modify val1 decimal(15,10);
  • change column name:
ALTER TABLE user CHANGE name newname CHAR(32) NOT NULL DEFAULT '123';
  • add default value:
ALTER TABLE user ALTER age SET DEFAUTL 18;
  • delete default value:
ALTER TABLE user ALTER age DROP DEFAULT;
  • add column:
ALTER TABLE `merchant_agings` ADD `aging_type` smallint DEFAULT 1 NOT NULL COMMENT '时效类型 1:小时 2:天';
  • add comment of table:
ALTER TABLE `merchant_agings` COMMENT '商家时效';
  • create table:
CREATE TABLE `merchant_products` (
    `id` INT(11) AUTO_INCREMENT PRIMARY KEY,
    `merchant_id` INT(11) NOT NULL,
    `merchant_name` VARCHAR(255) NOT NULL,
    `product_name` VARCHAR(255) NOT NULL,
    `created_at` DATETIME NOT NULL,
    `updated_at` DATETIME NOT NULL
)  ENGINE=INNODB;
  • insert value:
INSERT INTO schema_migrations (version) VALUES ('20171027020112');
  • grant tom with the password of 1234576 to access the users table:
grant all privileges on users.* to 'tom'@'%' identified by '123456';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment