php basics mysql

不言
Release: 2023-03-23 22:26:01
Original
1453 people have browsed it

This article introduces the basics of PHP mysql, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

mysql black window command

set names gbk Set the environment encoding name for connecting to the database (only this one in the black window)

show databases Display the created database list

drop database database name Delete database

create database chenchen Create database "chenchen"

create database chenche charset utf8

use database name use database (enter the database)

show tables Display table

mysql backup and recovery

Backup mysqldump -h localhost -u root -p wp5 > f:/123.sql


Restore

mysql -h localhost -u root -p chenchen1 < f:/123. sql


Create table

Modify table

Add a field

Delete a field

Modify a field

Delete table

 # 单行注释
 -- 注释内容(--后面带一个空格)
 /*
 注释内容
 */
 delimiter // #设定新的语句结束符
 #大小写问题
#-------------------------数据库定义语言 DDL-----------------------------

#创建数据库
create database chenchen charset utf8 collation utf8_general_ci
#显示数据库中的所有可用编码
show charset;
#显示mysql中的所有可用排序规则(utf8_general_ci utf8_bin)
show collation
#删除数据库
drop database if exists chenchen
#修改数据库(字符编码)
alter database chenchen charset utf8 collation utf8_general_ci

#显示所有数据库
show databases
#显示一个数据库的创建语句
show create database chenchen
#选择数据
use chenchen

# 数据(字段)类型:数字 字符型 时间型
#数字 tinyint smallint mediumint int bigint float double decimal
#日期时间 year timestamp time date datetime
#字符串型 set enum blob text varchar char
#常用字段类型  tinyint int float decimal timestamp date datetime set enum text varchar char
# tinyint 1个字节 8位 -128——127  八位一个字节
# int 4个字节 32位 
# bigint  8个字节 64位
#整数类型字段的设定形式:类型名 [M] [unsigned] [zerofill] m:显示长度 unsigned:无符号数没有负数 zerofill:0填充 
create table tab_int(f1 int,f2 tinyint,f3 bigint);
create table tab_int2(f1 int unsigned,f2 tinyint zerofill,f3 bigint(10) zerofill);
insert into tab_int2 values(1,1,1);
#float   单精度浮点型 4个字节存储数据,精度大约有6到7个有效数字位
#double  双精度浮点型 8个字节存储数据,精度大约只有20个有效数字位
#decimal (定点型)整数部分最长大概有65位,小数部分最长大概有30位,一般设置格式为 decimal(总位数,小数部分位数)
create table tab3(f1 float,f2 double,f3 decimal(10,2));
insert into tab3 values(1.28,100.9999,8888.012);
#字符类型 (用单引号)
#varchar 可变长度,必须定义长度(最多存储字符的个数),最大长度理论值 65535,实际最大值65533 gbk 65533/2 utf8 65533/3
#char  定长字符串,使用时设定其长度,不设定默认长度为1,最大理论长度是255
#enum  单选  enum("选项1","选项2","选项3"); 最多65533个选项 对应数字值 1.2.3.4.......65533
#set   多选  set("选项1","选项2","选项3"); 最多64个选项  对应数字值 1 2 4 8 16
# enum,set写入数据时可以用字符串本身也可以用对应的数字。set可以用对应数字的和。
#text 长文本类型
#其它
#binary 定长二进制字符串 varbinary 不定长二进制字符串 blob 二进制数据类型,存的仍然是二进制值,适用于存储图片、文件等
#时间类型
#datetime 日期时间
#date     日期
#time     时间
#year     年
#timestamp  时间戳(这个字段通常不用赋值)now()  md5()
#---------------------表定义-------------------------
create table if not exists tab4(id bigint(20) auto_increment primary key,name varchar(8) ,age int(4) ,phone varchar(12));
# primary key 主键 用于唯一确定一行数据
# unique key  唯一不能重复
# not null 不能为空
# default "xxx" 默认值 
# comment &#39;xxxxxx&#39;  字段说明
Copy after login

Related recommendations:

php basics Array

php basic function

The above is the detailed content of php basics mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!