mysql 基础操作命令记录
2017-08-16 12:39
876 查看
修改用户
先用root用户链接mysql
mysql -u root -p 回车 输入密码
然后 use mysql
然后执行修改用户命令 update set user='用户名' where user='原用户名'
flush privileges;刷新权限命令
查看数据库
mysql> show databases;
选择数据库
mysql> use bugfree;
设置字符集
mysql> set names 'gbk';
查询数据库中的表
mysql> show tables;
MySQL基本操作创建表
mysql> create table test(
-> tid int(10) not null,
-> tname varchar(100) not null,
-> tdate datetime not null default '0000-00-00',
-> primary key (tid));
查看表结构
mysql> desc test;
添加列
mysql> alter table test add(tage int(3));
修改原表结构
mysql> alter table test modify tage int(5) not null;
修改列的默认值
mysql> alter table test alter tage set default '0';
去掉列的默认值
mysql> alter table test alter tage drop default;
删除列
mysql> alter table test drop column tage;
插入数据
mysql> insert into test(tid,tname,tdate) value(1,'yangjuqi','2008-03-21');
查询数据
mysql> select * from test;
模糊查询
mysql> select * from test where tname like '%杨%';
修改数据
mysql> update test set tname='张三' where tid='2';
MySQL基本操作删除数据
mysql> delete from test where tid='2';
删除表
mysql>L> drop table test;
重命名表
mysql> alter table test rename testbak;
分页查询(limit 起始行,取多少行)
mysql> select * from testbak limit 2,1;
刷新数据库
mysql> flush privileges;
显示数据库版本
mysql> select version();
显示当前时间
mysql> select current_date;
将查询出的数据写入文件
mysql> select * from user into outfile "/etc/test.txt" fields terminated by ",";
查看数据库状态
mysql> status;
MySQL基本操作查看所有编码
mysql> show variables like 'character_set_%';
导入sql文件命令
mysql> source /etc/MySQL.sql;
先用root用户链接mysql
mysql -u root -p 回车 输入密码
然后 use mysql
然后执行修改用户命令 update set user='用户名' where user='原用户名'
flush privileges;刷新权限命令
查看数据库
mysql> show databases;
选择数据库
mysql> use bugfree;
设置字符集
mysql> set names 'gbk';
查询数据库中的表
mysql> show tables;
MySQL基本操作创建表
mysql> create table test(
-> tid int(10) not null,
-> tname varchar(100) not null,
-> tdate datetime not null default '0000-00-00',
-> primary key (tid));
查看表结构
mysql> desc test;
添加列
mysql> alter table test add(tage int(3));
修改原表结构
mysql> alter table test modify tage int(5) not null;
修改列的默认值
mysql> alter table test alter tage set default '0';
去掉列的默认值
mysql> alter table test alter tage drop default;
删除列
mysql> alter table test drop column tage;
插入数据
mysql> insert into test(tid,tname,tdate) value(1,'yangjuqi','2008-03-21');
查询数据
mysql> select * from test;
模糊查询
mysql> select * from test where tname like '%杨%';
修改数据
mysql> update test set tname='张三' where tid='2';
MySQL基本操作删除数据
mysql> delete from test where tid='2';
删除表
mysql>L> drop table test;
重命名表
mysql> alter table test rename testbak;
分页查询(limit 起始行,取多少行)
mysql> select * from testbak limit 2,1;
刷新数据库
mysql> flush privileges;
显示数据库版本
mysql> select version();
显示当前时间
mysql> select current_date;
将查询出的数据写入文件
mysql> select * from user into outfile "/etc/test.txt" fields terminated by ",";
查看数据库状态
mysql> status;
MySQL基本操作查看所有编码
mysql> show variables like 'character_set_%';
导入sql文件命令
mysql> source /etc/MySQL.sql;
相关文章推荐
- MySQL(5.5.48) 的基础操作命令(持续更新)
- mysql基础操作命令
- [转]使用tee记录mysql client 所有的操作,十个节省时间的mysql命令
- Python:Mysql编程(基础操作命令)
- mysql基础命令操作
- MySQL基础操作命令
- 整理的mysql基础操作命令
- mysql基础命令操作
- MySQL基础操作命令
- mysql命令(三)--操作数据表中的记录
- MySQL操作01_基础命令
- 记录MySQL的一些基础操作
- Mysql基础操作命令
- mysqlbinlog 命令筛选时间段某表操作记录
- mysql操作基础命令
- MySQL基础操作命令创建库DDL
- MongoDB 基础命令——数据库表的增删改查——遍历操作表中的记录
- Mysql 将结果保存到文件 从文件中执行sql语句 记录操作过程(tee 命令的使用)
- 常用mysql基础操作记录
- Mysql 将结果保存到文件 从文件里运行sql语句 记录操作过程(tee 命令的使用)