php basics mysql
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 'xxxxxx' 字段说明
Related recommendations:
The above is the detailed content of php basics mysql. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

Installing MySQL on macOS can be achieved through the following steps: 1. Install Homebrew, using the command /bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)". 2. Update Homebrew and use brewupdate. 3. Install MySQL and use brewinstallmysql. 4. Start MySQL service and use brewservicesstartmysql. After installation, you can use mysql-u

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.
