mysql登录数据库、基本命令
下⾯是⼏种登陆到MySql数据库的登陆⽅式代码
1mysql -u root -ppassword
Enter password:password
下载mysql服务端命令1.在登陆Mysql的时候有⼏点要注意的,在登陆数据库之前语句的结束⼀般是回车键,在登陆数据库后,mysql语句默认结束是;或者/g
2.在登陆密码登陆的时候,在明⽂密码时密码要在p参数后⾯,中间不能有间隔,输⼊完成后直接按回车键就可以了。
3.参数说明:-h是主机名 -u是⽤户名 -p是密码。
select user();
show databases;
create database bj_db charset utf8
use bj_db
create table t1(id int,score float);
show tables;
desc t1;
1:show databases;
查看所有的数据库,等同于select schema_name from information_schema.schemata\G。\G 替换;,以纵向报表的形式输出结果,有利于阅读。
2. status 查看mysql数据库的运⾏状态
3. use 命令选择数据库例如 use information_schema,当使⽤此命令后
select schema_name from information_schema.schemata\G,可以为
select schema_name from schemata\G
4. 查看数据库中的表
show tables
同样也可以在information_schema中查看,show命令是⽅便使⽤的简短模式。
select table_name from tables where table_schema='jblog';
5. 查看表结构
desc table_name;
6.查看表状态 show table status from db like 条件
可以查看engine数据库引擎,version,row、index等信息
7.⼩技巧,当多⾏命令输⼊,发现错误后,⽤\c结束。
-------------------------------------------------------------
另,查询数据库运⾏状态的基本命令:
#查询数据库连接
show full processlist;
show status like'%Max_used_connections%';
show status like'%Threads_connected%';#当前连接数
show status like'%table_lock%';#表锁定
show status like'innodb_row_lock%';#⾏锁定
show status like'%qcache%'; #查询缓存情况
show variables like"%query_cache%";
SHOW STATUS LIKE'Qcache%';
show variables like"%binlog%";
show status like'Aborted_clients';#由于客户没有正确关闭连接已经死掉,已经放弃的连接数量show variables like'%max_connections%';//查看最⼤连接数量
show variables like'%timeout%';#查看超时时间
show variables like'log_%'; #查看⽇志是否启动
1.操作⽂件夹(库):
增:create database db1 charset utf8
查:show create database db1;
show databases;
改:alter database db1 charset gbk;
删:drop database db1;
2.操作⽂件(表):
切换⽂件夹:
use db1;
select database();
增:create table t1(id int,name char);
查:show tables;
desc t1;
show create table t1;
show create table t1\G;
改:alter table t1 modify name char(6);
alter table t1 change name name1 char(7);
删:drop table t1;
3.操作⽂件内容(记录):
增:insert into t1(id,name) values(1,'alice1'),(2,'alice2'),(3,'alice3');
insert into t1 values(1,'egon1'),(2,'egon2'),(3,'egon3');
查:select id,name from db1.t1;
select id from db1.t1;
select * from db1.t1; # 不推荐使⽤ * 效率低
改:update db1.t1 set name='alex';
update t1 set name='egon' where id=2;
删:delete from t1;
delete from t1 where id=2;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论