13.3 mysql常用命令
2019独角兽企业重金招聘Python工程师标准>>>
mysql常用命令目录概要
- 查询库 show databases;
- 切换库 use mysql;
- 查看库里的表 show tables;
- 查看表里的字段 desc tb_name;
- 查看建表语句 show create table tb_name\G;
- 查看当前用户 select user();
- 查看当前使用的数据库 select database();
- 创建库 create database db1;
- 创建表 use db1; create table t1(
id
int(4),name
char(40)); - 查看当前数据库版本 select version();
- 查看数据库状态 show status;
- 查看各参数 show variables; show variables like 'max_connect%';
- 修改参数 set global max_connect_errors=1000;
- 查看队列 show processlist; show full processlist;
mysql常用命令
- mysql内部命令和linux系统命令不通用
- 库是由表组成,表是由字段组成
- 在mysql 中使用的命令需要使用分号 ; 结尾,否则会出问题
- 登录到mysql
[root@hf-01 ~]# mysql -uroot -p'hanfeng'
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.35 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
- 查看数据库 show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)mysql>
- 切换库 use mysql; ——>切换到哪一个库下面
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql>
- 列出所有的表 show tables;
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
28 rows in set (0.00 sec)mysql>
查看表里的字段 desc tb_name;
例子
- desc user; //查看user表里的所有字段;需要进入相关的库以后才能查看对应的表
查看建表语句 show create table tb_name\G;——>G 表示 竖排显示
例子
- show create table user\G;
查看当前用户 select user();
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)mysql>
- 这里的localhost 表示主机名,会反解析你的IP所属主机名
- 在mysql里面使用 方向键 可以查看之前使用的命令,和shell的命令类似,并且也有记录命令历史的功能,默认的缓存文件在 / 下,名字为“.mysql_history”
- 支持ctrl+l 清屏
- 查看当前使用的数据库 select database();
mysql> select database();
+------------+
| database() |
+------------+
| mysql |
+------------+
1 row in set (0.00 sec)mysql>
创建库
- 创建库 create database db1;
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)mysql>
- 查看db1库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)mysql>
- 切换到db1库下面去
mysql> use db1;
Database changed
mysql>
- 创建表 create table t1(
id
int(4),name
char(40));——>定义 id 和 name ,并用反引好括起来
mysql> create table t1(`id` int(4), `name` char(40));
Query OK, 0 rows affected (0.03 sec)mysql>
- 查看创建的表t1,默认使用的是InnoDB 引擎
mysql> show create table t1\G;
*************************** 1. row ***************************Table: t1
Create Table: CREATE TABLE `t1` (`id` int(4) DEFAULT NULL,`name` char(40) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)ERROR:
No query specifiedmysql>
- 在数据库里面取消命令,即在命令的最前面加一个 # 号就不会生效了
- 删除表 drop table t1;
mysql> drop table t1;
Query OK, 0 rows affected (0.02 sec)mysql>
- 创建t1表
mysql> create table t1(`id` int(4), `name` char(40)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.01 sec)mysql>
- 查看表,会看到变成了utf8
mysql> show create table t1\G;
*************************** 1. row ***************************Table: t1
Create Table: CREATE TABLE `t1` (`id` int(4) DEFAULT NULL,`name` char(40) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.01 sec)ERROR:
No query specifiedmysql>
- 查看当前数据库版本 select version();
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.35 |
+-----------+
1 row in set (0.00 sec)mysql>
查看数据库状态 show status; 它会把常用的数据都列出来
查看各参数
- show variables;
- show variables like 'max_connect%'; //mysql下 % 为通配符
mysql> show variables like 'max_connect%';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 100 |
| max_connections | 151 |
+--------------------+-------+
2 rows in set (0.00 sec)mysql>
- 修改参数 set global max_connect_errors=1000; ——>仅在内存中生效
mysql> set global max_connect_errors=1000;
Query OK, 0 rows affected (0.01 sec)mysql> show variables like 'max_connect%';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 1000 |
| max_connections | 151 |
+--------------------+-------+
2 rows in set (0.00 sec)mysql>
- 若想重启依然生效,那需要修改配置文件/etc/my.cnf
- 查看队列
- show processlist; //查看库的状况,比如,那些用户在连,做了些什么操作,是否锁表
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 14 | root | localhost | db1 | Query | 0 | init | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)mysql>
- show full processlist; //查看到的对列,最后一个会非常完成的显示出来
mysql> show full processlist;
+----+------+-----------+------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+-----------------------+
| 14 | root | localhost | db1 | Query | 0 | init | show full processlist |
+----+------+-----------+------+---------+------+-------+-----------------------+
1 row in set (0.00 sec)mysql>
转载于:https://my.oschina.net/u/3707314/blog/1605976
13.3 mysql常用命令相关推荐
- mysql tree 修改_13.1 设置更改root密码 13.2 连接mysql 13.3 mysql常用命令
更改root密码 ps aux |grep mysql //先查看一下mysql是否启动了 /etc/init.d/mysqld start //启动mysql ps aux |grep ...
- 13.1-13.3 设置更改root密码,连接MySQL,MySQL常用命令
13.1 设置更改root密码 大纲 准备工作: 1 启动mysql服务 [root@AliKvn ~]# /etc/init.d/mysqld start Starting MySQL. ...
- 征途linux mysql_MySql征途之mysql常用命令
mysql征程之mysql常用命令 一.连接MySql 语法: mysql -h 主机地址 -u 用户名 -p 用户密码 例1:连接到本机上的MYSQL.键入命令mysql -u root -p(本地 ...
- 设置更改root密码(远程,本地)、连接mysql、mysql常用命令
设置更改root密码 1.将mysql加入环境变量中 [root@centos7 ~]# grep mysql /etc/profile export PATH=/usr/local/mysql/bi ...
- 【CentOS 7MySQL常用操作3】,MySQL常用命令#180113
2019独角兽企业重金招聘Python工程师标准>>> hellopasswd MySQL常用命令 查询库show databases; 切换库use mysql; 查看库里的表sh ...
- mysql 更改root密码及 主机_设置更改root密码(远程,本地)、连接mysql、mysql常用命令...
设置更改root密码 1.将mysql加入环境变量中 [root@centos7 ~]# grep mysql /etc/profile export PATH=/usr/local/mysql/bi ...
- mysql root命令_设置更改root密码、连接mysql、mysql常用命令
目录 一.设置更改root密码 二.连接mysql 三.mysql常用命令 一.设置更改root密码 检查mysql服务是否启动 [root@minglinux-01 ~] ps aux |grep ...
- MySQL学习记录 (一) ----- 有关数据库的基本概念和MySQL常用命令
相关文章: <MySQL学习记录 (一) ----- 有关数据库的基本概念和MySQL常用命令> <MySQL学习记录 (二) ----- SQL数据查询语句(DQL)> &l ...
- Mysql常用命令行大全
Mysql常用命令行大全 第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名 -p用户密码 键 ...
最新文章
- python添加excel模块_python操作Excel模块openpyxl
- 拖动改变Table的列宽度
- Pycharm安装pip pip安装第三方模块
- @ControllerAdvice这个注解主要作用是什么
- 「Self-driving: Perception」感知总览
- .NET对象克隆的深究(转)
- linux下搭建简单的git服务器测试1
- java super object,java学习记录笔记--继承,super,Object类
- emctl start dbconsole OC4J_dbconsole*** not found
- vis.js入门_使用TensorBoard数据Vis的TensorFlow手术分类器入门
- 跨年照片墙php源码,简单效果照片墙
- 小区进入刷卡,快递不方便
- windows C++ 网络编程
- 推荐系统—基于用户的协同过滤算法简单实现
- MYSQL存储过程的简单运用,包括传值、返回值、返回集合
- 征途服务器关闭注册,你不是一个人 征途手机版老服务器的进入法则
- 报告分析工具创建完美的分析报告
- 建网站如何选择空间?
- 4位先行进位加法器的vhdl程序_VHDL精密,Verilog简洁,但要写好都要遵守这25条通则...
- 倍福beckhoff详细知识库展示