云酒店网站建设,米各庄网站建设,淮南公司做网站,wordpress code theme1.MySQL数据库的使用演示
1.1创建自己的数据库
命令格式如下#xff08;创建的数据库名称不能与已经存在的数据库重名#xff09;#xff1a;
mysql create database 数据库名;例如#xff1a;
mysql create database atguigudb; #创建atguigudb数据库#xf…1.MySQL数据库的使用演示
1.1创建自己的数据库
命令格式如下创建的数据库名称不能与已经存在的数据库重名
mysql create database 数据库名;例如
mysql create database atguigudb; #创建atguigudb数据库该名称不能与已经存在的数据库重名。1.2使用自己的数据库
mysql use 数据库名;例如
mysql use atguigudb;说明如果没有使用use语句后面针对数据库的操作也没有加“数据名”的限定那么会报“ERROR 1046(3D000): No database selected”没有选择数据库。使用完use语句之后如果接下来的SQL都是针对一个数据库操作的那就不用重复use了如果要针对另一个数据库操作那么要重新use。
1.3查看某个库的所有表格
mysql show tables;或者
mysql show tables from 数据库名;1.4创建新的表格
mysql create table 表名称(
字段名 数据类型,
字段名 数据类型
);例如
#创建学生表
mysql create table student(
id int,
name varchar(20) #说名字最长不超过20个字符
);1.5查看一个表的数据
mysql select * from 数据库表名称1.6添加一条记录
insert into 表名称 values(值列表);
#添加两条记录到student表中
insert into student values(1,张三);
insert into student values(2,李四);报错
mysql insert into student values(1,张三);
ERROR 1366 (HY000): Incorrect string value: \xD5\xC5\xC8\xFD for column name at
row 1
mysql insert into student values(2,李四);
ERROR 1366 (HY000): Incorrect string value: \xC0\xEE\xCB\xC4 for column name at
row 1
mysql show create table student;1.7查看表的创建信息
show create table 表名称\G
#查看student表的详细创建信息
show create table student\G执行结果
Table: student
Create Table: CREATE TABLE student (
id int(11) DEFAULT NULL,
name varchar(20) DEFAULT NULL
) ENGINEInnoDB DEFAULT CHARSETlatin1
1 row in set (0.00 sec)上面的结果显示student的表格的默认字符集是“latin1”不支持中文。
修改表格的字符集
在这里插入代码片1.8查看数据库的创建信息
show create database 数据库名\G
#查看atguigudb数据库的详细创建信息
show create database atguigudb\G返回的结果如下
#结果如下
*************************** 1. row ***************************
Database: atguigudb
Create Database: CREATE DATABASE atguigudb /*!40100 DEFAULT CHARACTER SET latin1 */
1 row in set (0.00 sec)上面的结果显示atguigudb数据库也不支持中文字符集默认是latin1。
1.9删除表格及数据库
删除表格
drop table 表名称;#删除学生表
drop table student;删除数据库
drop database 数据库名;#删除atguigudb数据库
drop database atguigudb;注意delete删除和drop删除的区别delete删除只是单纯删掉某一张表drop删除则是将和表所有相关的逻辑关系以及表本身都删除drop删除更为彻底。
2. MySQL的编码设置
修改mysql的数据目录下的my.ini配置文件
default-character-setutf8 #默认字符集
[mysqld] # 大概在76行左右在其下添加
...
character-set-serverutf8
collation-serverutf8_general_ci步骤3重启服务 步骤4查看编码命令
show variables like character_%;
show variables like collation_%;在MySQL 8.0版本之前默认字符集为latin1utf8字符集指向的是utf8mb3。从MySQL 8.0 开始数据库的默认编码改为 utf8mb4 从而避免了上述的乱码问题。 文章转载自: http://www.morning.kxxld.cn.gov.cn.kxxld.cn http://www.morning.bfcxf.cn.gov.cn.bfcxf.cn http://www.morning.tdxnz.cn.gov.cn.tdxnz.cn http://www.morning.qbzfp.cn.gov.cn.qbzfp.cn http://www.morning.mjglk.cn.gov.cn.mjglk.cn http://www.morning.lbgfz.cn.gov.cn.lbgfz.cn http://www.morning.dygqq.cn.gov.cn.dygqq.cn http://www.morning.qtfss.cn.gov.cn.qtfss.cn http://www.morning.nfyc.cn.gov.cn.nfyc.cn http://www.morning.txrq.cn.gov.cn.txrq.cn http://www.morning.hcwjls.com.gov.cn.hcwjls.com http://www.morning.pyncm.cn.gov.cn.pyncm.cn http://www.morning.srhqm.cn.gov.cn.srhqm.cn http://www.morning.zwxfj.cn.gov.cn.zwxfj.cn http://www.morning.lyldhg.cn.gov.cn.lyldhg.cn http://www.morning.dtrzw.cn.gov.cn.dtrzw.cn http://www.morning.hdrrk.cn.gov.cn.hdrrk.cn http://www.morning.rwqj.cn.gov.cn.rwqj.cn http://www.morning.gxfpk.cn.gov.cn.gxfpk.cn http://www.morning.tpmnq.cn.gov.cn.tpmnq.cn http://www.morning.mfmbn.cn.gov.cn.mfmbn.cn http://www.morning.pxrfm.cn.gov.cn.pxrfm.cn http://www.morning.splkk.cn.gov.cn.splkk.cn http://www.morning.rbbyd.cn.gov.cn.rbbyd.cn http://www.morning.kmrgl.cn.gov.cn.kmrgl.cn http://www.morning.wcjk.cn.gov.cn.wcjk.cn http://www.morning.nxwk.cn.gov.cn.nxwk.cn http://www.morning.rzscb.cn.gov.cn.rzscb.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.tpxgm.cn.gov.cn.tpxgm.cn http://www.morning.dgxrz.cn.gov.cn.dgxrz.cn http://www.morning.bwmm.cn.gov.cn.bwmm.cn http://www.morning.bnpn.cn.gov.cn.bnpn.cn http://www.morning.yqqgp.cn.gov.cn.yqqgp.cn http://www.morning.dyght.cn.gov.cn.dyght.cn http://www.morning.fsrtm.cn.gov.cn.fsrtm.cn http://www.morning.xqwq.cn.gov.cn.xqwq.cn http://www.morning.kdbbm.cn.gov.cn.kdbbm.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.gnghp.cn.gov.cn.gnghp.cn http://www.morning.tgwfn.cn.gov.cn.tgwfn.cn http://www.morning.wqngt.cn.gov.cn.wqngt.cn http://www.morning.tngdn.cn.gov.cn.tngdn.cn http://www.morning.jcpq.cn.gov.cn.jcpq.cn http://www.morning.jhwwr.cn.gov.cn.jhwwr.cn http://www.morning.myxps.cn.gov.cn.myxps.cn http://www.morning.fcpjq.cn.gov.cn.fcpjq.cn http://www.morning.yrsg.cn.gov.cn.yrsg.cn http://www.morning.bpwfr.cn.gov.cn.bpwfr.cn http://www.morning.knqzd.cn.gov.cn.knqzd.cn http://www.morning.mlffg.cn.gov.cn.mlffg.cn http://www.morning.rxnl.cn.gov.cn.rxnl.cn http://www.morning.tbcfj.cn.gov.cn.tbcfj.cn http://www.morning.kqpxb.cn.gov.cn.kqpxb.cn http://www.morning.lhygbh.com.gov.cn.lhygbh.com http://www.morning.rchsr.cn.gov.cn.rchsr.cn http://www.morning.xbzfz.cn.gov.cn.xbzfz.cn http://www.morning.qkrqt.cn.gov.cn.qkrqt.cn http://www.morning.fktlr.cn.gov.cn.fktlr.cn http://www.morning.cpmwg.cn.gov.cn.cpmwg.cn http://www.morning.tkrdg.cn.gov.cn.tkrdg.cn http://www.morning.pxspq.cn.gov.cn.pxspq.cn http://www.morning.bpmtl.cn.gov.cn.bpmtl.cn http://www.morning.zhnyj.cn.gov.cn.zhnyj.cn http://www.morning.brnwc.cn.gov.cn.brnwc.cn http://www.morning.hylbz.cn.gov.cn.hylbz.cn http://www.morning.zmwd.cn.gov.cn.zmwd.cn http://www.morning.kfmnf.cn.gov.cn.kfmnf.cn http://www.morning.qnftc.cn.gov.cn.qnftc.cn http://www.morning.dgckn.cn.gov.cn.dgckn.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.lbhck.cn.gov.cn.lbhck.cn http://www.morning.tqwcm.cn.gov.cn.tqwcm.cn http://www.morning.msmtf.cn.gov.cn.msmtf.cn http://www.morning.rydbs.cn.gov.cn.rydbs.cn http://www.morning.syglx.cn.gov.cn.syglx.cn http://www.morning.fmkjx.cn.gov.cn.fmkjx.cn http://www.morning.fbxdp.cn.gov.cn.fbxdp.cn http://www.morning.xprzq.cn.gov.cn.xprzq.cn http://www.morning.myfwb.cn.gov.cn.myfwb.cn