mysql常用命令

检查是否安装成功:sudo netstat -tap | grep mysql

进入mysql:mysql -u root -p;

退出msyql:exit;

重启mysql:sudo /etc/init.d/mysql restart

 

查看mysql版本:mysqladmin -u root -p version

查看当前所有数据库:show databases;

选择数据库:use mydata;

创建数据库:create database test1;

删除数据库:drop database test1;

显示表数据结构:describe 表名

 

修改密码:mysqladmin -u用户名 -p旧密码 password 新密码

创建数据表:create table <表名> ( <字段名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));

 

drop table MyClass; # 删除表

alter table 表名 add字段 类型; # 增加表字段

    如:alter table MyClass add passtest int(4) default '0'

alter table table_name DROP field_name; # 删除表字段

modify column `department_name`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL; # 修改列

ALTER TABLE `t_distributor_purchase_order` ADD INDEX order_type ( `order_type` );  ## 添加索引

alter table drop index `mobile_phone`;  # 删除索引

alter table `t_store_image` add column `id` int not null auto_increment primary key comment '主键' first;   #添加列,并设置主键自增长

alter table `t_tires_special_offer` modify column `distributor_ids` varchar(5000);  ## 修改表列字段长度

 

## 查询是否有锁表

select * from information_schema.INNODB_LOCKS;

select * from information_schema.INNODB_LOCK_WAITS;

 

设置字符集(以utf8为例):

  1) 查看当前的编码:show variables like 'character%';

  2) 修改my.cnf,在[client]下添加default-character-set=utf8

  3) 修改[mysqld]下添加character-set-server=utf8

  4) 重启mysql。 

 

安装 mysql

sudo apt-get install mysql-server

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值