zoukankan      html  css  js  c++  java
  • 常用SQL语句备忘

    1.linux环境下启动/停止mysql服务

    启动  sudo start mysql

    停止  sudo stop mysql

    2.用户登录

    (请注意-p和密码之间不能有空格,如果不输入password,回车后会出现Enter password的提示。如果root密码为空,也不需要输入password,出现Enter password提示后回车即可。)

    mysql -u 用户名 -p[密码] [默认链接哪一个数据库]

    ag:root用户登录,不链接任何数据库

    mysql -u root -p

    ag:root用户登录,链接test这个数据库

    mysql -u root -p test

    3.修改root用户的密码(如果root默认密码为空,则不需要输入,如果需要更改老密码,请注意-p与旧密码之间不要有空格,password和新密码之间以空格分隔)

    mysqladmin -u root -p[旧密码] password 新密码

    ag:mysqladmin -u root -p123456 password bingo

    4.创建/删除用户

    创建用户,用户名:bingo,密码:bingo

    create user 'bingo'@'localhost' identified by 'bingo';

    如果想不限制链接的 IP 则设置为“%”即可

    删除用户

    drop user 'bingo'@'localhost';

    5.创建/删除数据库

    创建一个数据库,数据库名:algorithm,默认字符集:utf8

    create database algorithm default character set utf8;

    删除数据库

    drop database algorithm;

    使用algorithm这个数据库

    use algorithm;

    6.把对algorithm这个数据库里所有的表的所有操作权限赋给bingo这个用户

     grant all privileges on algorithm.* to 'bingo'@'localhost';

     grant all privileges on *.* to 'root'@'%' with grant option;

     

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pwd' WITH GRANT OPTION;

    7.mysql只导出建表语句

    mysqldump --no-data -u username -p* algorithmhome > algorithmhome.sql

    mysqldump -uroot -p* algorithmhome >algorithmhome.sql

    8.导入sql文件

    use 数据库;

    source /home/bingo/backpack.sql;

    9.给表添加新字段

    ALTER TABLE 表名 ADD 字段名 tinyint(1) NOT NULL DEFAULT '1' COMMENT '注释';

    10.删除某一列

    ALTER TABLE 表名 DROP 字段名;

  • 相关阅读:
    BEC listen and translation exercise 44
    中译英12
    BEC listen and translation exercise 43
    中译英11
    BEC listen and translation exercise 42
    中译英10
    BEC listen and translation exercise 41
    中译英9
    BEC listen and translation exercise 40
    中译英8
  • 原文地址:https://www.cnblogs.com/bingoogol/p/mysql-generic.html
Copyright © 2011-2022 走看看