mysql登录数据库、基本命令
MySQL登录数据库
下面是几种登陆到MySql数据库的登陆方式代码
1mysql -u root -ppassword
2.mysql -u root -p
Enter password:password
3.mysql -h localhost -u root -ppassword
4.mysql -h 127.0.0.1 -u root -ppassword
1.在登陆Mysql的时候有几点要注意的,在登陆数据库之前语句的结束一般是回车键,在登陆数据库后,mysql语句默认结束是;或者/g


2.在登陆密码登陆的时候,在明文密码时密码要在p参数后面,中间不能有间隔,输入完成后直接按回车键就可以了。
3.参数说明:-h是主机名 -u是用户名 -p是密码。
mysql 查看数据库、表的基本命令
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;
浙公网安备 33010602011771号