Mysql常用命令汇总 |
一、Mysql安装目录 二、系统管理 复制代码 代码如下: hadoop@ubuntu:'$ mysql -uroot -pmysql;
例 2:连接到远程主机上的MYSQL 。 复制代码 代码如下: hadoop@ubuntu:'$ mysql -h 127.0.0.1 -uroot -pmysql;
修改新密码 > use mysql; > update user set password=PASSWORD(新密码) where user=用户名; > flush privileges; #更新权限 > quit; #退出 增加新用户 复制代码 代码如下: mysql>grant select,insert,update,delete on *.* to root@localhost identified by mysql; 或者 复制代码 代码如下: grant all privileges on *.* to root@localhost identified by mysql; 然后刷新权限设置:flush privileges; 例 2:如果你不想 root 有密码操作数据库“mydb”里的数据表,可以再打一个命令将密码消掉 。 复制代码 代码如下: grant select,insert,update,delete on mydb.* to root@localhost identified by ;
删除用户 hadoop@ubuntu:'$ mysql -u用户名 -p密码 mysql>delete from user where user=用户名 and host=localhost; mysql>flush privileges; //删除用户的数据库 mysql>drop database dbname; 三、数据库操作 创建数据库:mysql> create database test; 连接数据库:mysql> use test; 查看当前使用的数据库:mysql> select database(); 当前数据库包含的表信息:mysql> show tables; (注意:最后有个 s) 删除数据库:mysql> drop database test; 四、表操作 mysql> 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)); 获取表结构命令: desc 表名,或者show columns from 表名 mysql> describe MyClass mysql> desc MyClass; mysql> show columns from MyClass; 删除表命令:drop table <表名> 复制代码 代码如下: mysql> drop table MyClass;
插入数据命令:insert into <表名> [( <字段名 1>[,..<字段名 n > ])] values ( 值 1 )[, ( 值 n )] 复制代码 代码如下: mysql> insert into MyClass values(1,Tom,96.45),(2,Joan,82.99), (2,Wang, 96.59);
查询表中的数据 查询前几行数据 复制代码 代码如下: mysql> select * from MyClass order by id limit 0,2; 或者 复制代码 代码如下: mysql> select * from MyClass limit 0,2;
删除表中数据命令:delete from 表名 where 表达式 复制代码 代码如下: mysql> delete from MyClass where id=1;
修改表中数据命令:update 表名 set 字段=新值,... where 条件 复制代码 代码如下: mysql> update MyClass set name=Mary where id=1;
在表中增加字段命令:alter table 表名 add 字段 类型 其他; 复制代码 代码如下: mysql> alter table MyClass add passtest int(4) default 0
更改表名命令:rename table 原表名 to 新表名; 复制代码 代码如下: mysql> rename table MyClass to YouClass;
更新字段内容命令:update 表名 set 字段名 = 新内容 复制代码 代码如下: update article set content=concat( , content);
五、数据库导入导出 2)导出数据和数据结构 例2:将数据库 mydb 中的 mytable 导出到 e:\MySQL\mytable.sql 文件中 。 例3:将数据库 mydb 的结构导出到 e:\MySQL\mydb_stru.sql 文件中 。 3)只导出数据不导出数据结构 4)导出数据库中的Events 5)导出数据库中的存储过程和函数 从外部文件导入数据库中 2)使用“<”符号 以上就是Mysql常用命令汇总,希望对大家的学习有所帮助 。 |