Table of Contents
mysql black window command

php basics mysql

May 15, 2018 pm 03:51 PM
mysql php Base

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

See all articles