3Mysql 的常用操作

[email protected] ~]# mysql -uroot -pzaq12wsx   #入库

mysql> show databases;  #查库

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    24

Current database: *** NONE ***

+--------------------+

| Database           |

+--------------------+

| information_schema |

| discuz             |

| mysql              |

| test               |

+--------------------+

4 rows in set (0.04 sec)

mysql> use mysql   #切换库

No connection. Trying to reconnect...

Connection id:    25

Current database: *** NONE ***

Database changed

#切换了库以后,我们如怎么确认我们当前是在哪个库下

mysql> select database();# 查看当前数据库的命令

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    28

Current database: discuz

+------------+

| database() |

+------------+

| discuz     |

+------------+

1 row in set (0.00 sec)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mysql> select version();# 查看软件的版本

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    30

Current database: discuz

+------------+

| version()  |

+------------+

| 5.1.73-log |

+------------+

1 row in set (0.00 sec)

——————————————————————————————————————————————

库--> 表--> 行 --> 字段

mysql> show tables; # 查库

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    31

Current database: discuz

+-----------------------------------+

| Tables_in_discuz                  |

+-----------------------------------+

| pre_common_admincp_cmenu          |

| pre_common_admincp_group          |

| pre_common_admincp_member         |#下略,太多

| pre_common_admincp_perm           |

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

查看表的字段

mysql> desc  pre_ucenter_vars; #查看表的字段

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    32

Current database: discuz

+-------+-----------+------+-----+---------+-------+

| Field | Type      | Null | Key | Default | Extra |

+-------+-----------+------+-----+---------+-------+

| name  | char(32)  | NO   | PRI |         |       |

| value | char(255) | NO   |     |         |       |

+-------+-----------+------+-----+---------+-------+

2 rows in set (0.02 sec)

mysql> show create table pre_ucenter_vars\G;  #查询表的创建语句

*************************** 1. row ***************************

Table: pre_ucenter_vars

Create Table: CREATE TABLE `pre_ucenter_vars` (

`name` char(32) NOT NULL DEFAULT ‘‘,

`value` char(255) NOT NULL DEFAULT ‘‘,

PRIMARY KEY (`name`)

) ENGINE=MEMORY DEFAULT CHARSET=gbk

1 row in set (0.00 sec)

ERROR:

No query specified

##############################################################################################

手动创建一个库

mysql> create database obird; # 创建库名

mysql> use obird;             # 进入创建库

mysql> create table tb1 (`id` int(4), `name` char(40)) ENGINE=MyISAM DEFAULT CHARSET=gbk;

#创建表名  tb1,表内的字段   int(长度是4位),char(最长40),ENGINE ,字符集=gbk

mysql> show tables;

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    41

Current database: obird

+-----------------+

| Tables_in_obird |

+-----------------+

| tb1             |

+-----------------+

1 row in set (0.00 sec)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mysql> desc tb1;

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    42

Current database: obird

+-------+----------+------+-----+---------+-------+

| Field | Type     | Null | Key | Default | Extra |

+-------+----------+------+-----+---------+-------+

| id    | int(4)   | YES  |     | NULL    |       |

| name  | char(40) | YES  |     | NULL    |       |

+-------+----------+------+-----+---------+-------+

2 rows in set (0.00 sec)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mysql> show create table tb1\G;

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    44

Current database: obird

*************************** 1. row ***************************

Table: tb1

Create Table: CREATE TABLE `tb1` (

`id` int(4) DEFAULT NULL,

`name` char(40) DEFAULT NULL

) ENGINE=MyISAM DEFAULT CHARSET=gbk

1 row in set (0.00 sec)

ERROR:

No query specified

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

在表内插入数据

mysql> insert into tb1 values(1,‘aming‘);

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    45

Current database: obird

Query OK, 1 row affected (0.00 sec)

mysql> select * from tb1; # 查询

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    46

Current database: obird

+------+-------+

| id   | name  |

+------+-------+

|    1 | aming |

+------+-------+

1 row in set (0.00 sec)

继续插入

mysql> insert into tb1 values(2,‘linux‘);

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    47

Current database: obird

Query OK, 1 row affected (0.00 sec)

mysql> select * from tb1;  #再次查询

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    48

Current database: obird

+------+-------+

| id   | name  |

+------+-------+

|    1 | aming |

|    2 | linux |

+------+-------+

2 rows in set (0.00 sec)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

只插一个字段

mysql> insert into tb1 (`id`) values(2);

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    49

Current database: obird

Query OK, 1 row affected (0.00 sec)

mysql> select * from tb1;

+------+-------+

| id   | name  |

+------+-------+

|    1 | aming |

|    2 | linux |

|    2 | NULL  |# 只插入一个字段ID,name 此处是空的

+------+-------+

3 rows in set (0.00 sec)

mysql> insert into tb1 (`name`) values(‘test‘);

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    50

Current database: obird

Query OK, 1 row affected (0.00 sec)

mysql> select * from tb1;

+------+-------+

| id   | name  |

+------+-------+

|    1 | aming |

|    2 | linux |

|    2 | NULL  |

| NULL | test  |# 只插入name ,ID 是空

+------+-------+

4 rows in set (0.00 sec)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

也可以花式插法,id&name 互换,但是要一一对应

mysql> insert into tb1 (`name`,`id`) values(‘77‘,6);

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    51

Current database: obird

Query OK, 1 row affected (0.00 sec)

mysql> select * from tb1;

+------+-------+

| id   | name  |

+------+-------+

|    1 | aming |

|    2 | linux |

|    2 | NULL  |

| NULL | test  |

|    6 | 77    |

+------+-------+

5 rows in set (0.00 sec)

##############################################################################################

更新一条数据

mysql> update tb1 set id=8 where name = ‘77‘; #name = 77 的只有一行,改成了 “8”

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    52

Current database: obird

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from tb1;

+------+-------+

| id   | name  |

+------+-------+

|    1 | aming |

|    2 | linux |

|    2 | NULL  |

| NULL | test  |

|    8 | 77    |

+------+-------+

5 rows in set (0.00 sec)

删除一行

mysql> delete from tb1 where name=‘77‘;# 删除指定的一行 77

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    54

Current database: obird

Query OK, 1 row affected (0.00 sec)

mysql> select * from tb1;

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    57

Current database: obird

+------+-------+

| id   | name  |

+------+-------+

|    1 | aming |

|    2 | linux |

|    2 | NULL  |

| NULL | test  |

+------+-------+ # 查询不到 77 的行

4 rows in set (0.00 sec)

清空一张表

mysql> truncate table obird.tb1; #清空一张表

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    59

Current database: obird

Query OK, 0 rows affected (0.00 sec)

mysql> select * from tb1;  # 表已经空了

Empty set (0.00 sec)

干掉整张表

mysql> drop table tb1;  #语法

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    60

Current database: obird

Query OK, 0 rows affected (0.00 sec)

mysql> select * from tb1;

ERROR 1146 (42S02): Table ‘obird.tb1‘ doesn‘t exist  #报错表已经不存在

干掉 obird 这个库

mysql> show databases; #查询,obird 这个库是存在的

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    61

Current database: obird

+--------------------+

| Database           |

+--------------------+

| information_schema |

| discuz             |

| mysql              |

| obird              |

| test               |

+--------------------+

5 rows in set (0.00 sec)

mysql> drop database obird; # 干掉库的语法

ERROR 2006 (HY000): MySQL server  has gone away

No connection. Trying to reconnect...

Connection id:    62

Current database: obird

Query OK, 0 rows affected (0.01 sec)

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| discuz             |

| mysql              |

| test               |#再查询,obird 已经不在了。

+--------------------+

4 rows in set (0.00 sec)

##############################################################################################

时间: 2024-12-11 17:26:51

3Mysql 的常用操作的相关文章

Python 字典的特点和常用操作

一.字典帮助文档 >>> dir(dict) ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt

postgresql的ALTER常用操作

postgresql版本:psql (9.3.4) 1.增加一列ALTER TABLE table_name ADD column_name datatype; 2.删除一列 ALTER TABLE table_name DROP column_name; 3.更改列的数据类型 ALTER TABLE table_name ALTER column_name TYPE datatype; 4.表的重命名 ALTER TABLE table_name RENAME TO new_name; 5.更

Mysql数据库常用操作

1.备份数据库 [[email protected] ~]# mysqldump -h 192.168.0.8 -uroot  -p'123456'  user >user.sql 2.查看mysql数据库字符集设置 mysql> show variables like 'character_set_%';+--------------------------+----------------------------+| Variable_name            | Value    

多路径软件常用操作(MPIO)

一:查看存储盘的路径 1. 查看MPIO的存储盘的路径 # lspath (适用于所有存储的MPIO路径查询) # mpio_get_config -Av (适用于DS3K/DS4K的MPIO路径查询) 2. 查看RDAC存储盘的路径 # fget_config -Av (适用于DS3K/DS4K的RDAC路径查询) 3.查看SDDPCM存储盘的路径 # pcmpath query device (适用于DS6K/DS8K和v7000的SDDPCM路径查询) 4. 查看当前操作系统自带的支持IB

Python学习笔记五:字符串常用操作,字典,三级菜单实例

字符串常用操作 7月19日,7月20日 ,7月22日,7月29日,8月29日,2月29日 首字母大写:a_str.capitalize() 统计字符串个数:a_str.count("x") 输出字符,不够的使用指定的字符补上,字符居中:a_str.center(50,"-") 判断字符串以什么结尾:a_str.endwith("xx") 将字符串中的tab转换为指定数目的空格:a_str.expandtabs(tabsize=30) 查找指定字符

jQuery的常用操作

梳理一下jQuery的常用操作 jQuery隐藏显示对象 id为test的元素的display修改成了"none",即隐藏了id为test的元素:$('#test').css('display','none') 或 $('#test').style.display="none" 我们经常用到的是切换一个元素的隐藏与现实,下面给出代码: var show = $('#test').css('display');//获取id为test的元素的display的值$('#t

MongoDB常用操作

1.MongoDB常用操作 1.1数据库的操作命令 1.创建数据库,使用命令 use 数据库名称 ,如 use sxf. *注意: 1.use 命令后跟的数据库名,如果存在就进入此数据库,如果不存在就创建,所以这种创建方式又叫隐式创建 2.使用命令use sxf创建数据库后,并没有真正生成对应的数据文件,如果此时退出,此数据库将被删除,只有在此数据库中创建集合后,才会真正生成数据文件 2. 删除当前数据库,使用命令 db.dropDatabase() 3.查看所有数据库,使用命令 show db

git bash 常用操作文件命令

git bash常用操作文件命令 在Windows下使用Git Bash,用的是Linux命令,常用几个文件操作命令如下: Windows命令 Linux 命令 意义 Windows命令 Linux 命令 意义 cd e:\xxx cd /e/xxx 切换到xxx目录 cd pwd 显示当前目录路径 dir ls 列出当前目录内容 copy nul xxx.txt touch xxx.txt 生成名为xxx.txt的空文件 del xxx.txt rm xxx.txt 删除xxx.txt文件 m

位运算常用操作总结位运算应用口诀清零取反要用与,某位置一可用或若要取反和交换,轻轻松松用异或移位运

来源:http://www.educity.cn/wenda/381487.html 位运算常用操作总结位运算应用口诀 清零取反要用与,某位置一可用或 若要取反和交换,轻轻松松用异或 移位运算 要点 1 它们都是双目运算符,两个运算分量都是整形,结果也是整形.     2 " $amp;     3 "$amp;>amp;>quot;$右移:右边的位被挤掉.对于左边移出的空位,如果是正数则空位补0,若为负数,可能补0或补1,这取决于所用的计算机系统.     4 "