zoukankan      html  css  js  c++  java
  • MySQL常用命令

    1、MySQL服务的启动和停止

    net stop mysql
    net start mysql

    2、登录MySQL

    mysql -u 用户名 -p 用户密码

    键入命令mysql -u root -p, 回车后提示输入密码,然后回车即可进入到mysql中,mysql的提示符是:mysql>

    注意,如果是连接到另外的机器上,则需要加入一个参数 -h 机器IP

    3、增加新用户

    grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"

      增加一个用户user1密码为password1,让其可以在本机上登录, 并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入mysql,然后键入以下命令:

    grant select,insert,update,delete on *.* to user1@localhost Identified by "password1";

      如果希望该用户能够在任何机器上登陆mysql,则将localhost改为"%"。

    4、显示数据库列表

    show databases;

      缺省有两个数据库:mysql和test。 mysql库存放着mysql的系统和用户权限信息,我们改密码和新增用户,实际上就是对这个库进行操作。

    5、显示库中的数据表

    use mysql;
    show tables;

    6、显示数据表的结构

    describe 表名;

    7、建库与删库

    create database 库名;
    drop database 库名;

    8、建表与删表

    use 库名;
    create table 表名(字段列表);
    drop table 表名;

      创建一个数据表:

    create table mytable (name VARCHAR(20), sex CHAR(1));

    9、往表中增加一条记录

    insert into test1 values("hyq","M");

    10、清空表中记录

    delete from 表名;

    11、更新表中数据

    update test1 set sex="f" where name='hyq';

    12、显示表中记录

    select * from 表名;

    13、导出数据

    mysqldump --opt test1 > mysql.test;

      即将数据库test1导出到mysql.test文件,后者是一个文本文件;

    mysqldump -u root -p --databases test1 > mysql.dbname

      就是把数据库test1导出到文件mysql.dbname中;

    14、导入数据

    mysqlimport -u root -p 123456 < mysql.dbname

    15、将文本数据导入数据库(文本数据的字段数据之间用tab键隔开)

    use test1;
    load data local infile "E:123.txt" into table test1;

      将E盘123.txt文件中的数据导入到数据库test1的test1数据表(已建立)中

    16、导入.sql文件(例如D:/mysql.sql)

    use test1;
    source d:/mysql.sql;

    17、备份数据库

    mysqldump -u root 库名>xxx.data;

    18、退出MySQL

    exit
    =======================================================================
    中文名:高洪臣
    英文名:Gordon Scott
    E-mail:gaohongchen01@163.com
    =======================================================================
  • 相关阅读:
    mysql命令集锦
    linux 删除文件名带括号的文件
    linux下的cron定时任务
    struts2文件下载的实现
    贴一贴自己写的文件监控代码python
    Service Unavailable on IIS6 Win2003 x64
    'style.cssText' is null or not an object
    "the current fsmo could not be contacted" when change rid role
    远程激活程序
    新浪图片病毒
  • 原文地址:https://www.cnblogs.com/gaohongchen01/p/4007345.html
Copyright © 2011-2022 走看看