MySql常用命令

来源:互联网 发布:g3营销软件 编辑:程序博客网 时间:2024/06/14 02:09
  1. 登陆,如果没有在环境变量中配置路径,则需要定位到mysql安装的bin目录,输入mysql -uroot -p,回车,输入密码,回车。
  2. 修改密码:
    1. set password for root@localhost = password(‘root’);
    2. mysqladmin -uroot -p123456 password 123;
  3. select version(); 查看mysql版本。
  4. status;查看mysql详细信息。
  5. show databases 显示所有数据库。
  6. show variables like ‘%datadir%’ 显示数据库存放路径。
  7. create database dataname 创建名为dataname的数据库
  8. drop database dataname 删除名为dataname的数据库
  9. drop database if exists dataname 删除一个不一定存在的数据库
  10. use smart 连接(使用)名为smart的数据库
  11. create table tablename (<字段名1><类型1> [,…<字段名n><类型n>]); 创建数据表,例:
> create table myclass(> id int(4) not null primary key auto_increment,> name char(20) not null,> sex int(4) not null default '0',> degree double(16,2));
  1. show tables; 显示数据表。
  2. describe tableName;显示表结构。
  3. drop table tablename; 删除数据表
  4. insert into user(userName, password, email) values(‘zhibo405’, ‘zhibo405’, ‘444894216@qq.com’);插入时可以不写自增的主键。
  5. 查找:
    1. select * from tablename;查询所有信息
    2. select sex from myclass where name=’Tom’;
  6. 删除:
    1. delete from myclass where name=’Tom’;
    2. delete from table; 清空表
  7. 更改:
    1. update myclass set sex=1 where name=’Tom’;
    2. update mycalss set sex=1,age=2 where name=”Tom”;
  8. alter table t1 rename t2; 修改表名
  9. alter table t2 add c varchar(30);增加列
  10. alter table t2 modify a tinyint not null, change b c char(20);修改列
  11. alter table t2 drop column c; 删除列
0 0
原创粉丝点击