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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

The Future of PHP: Adaptations and Innovations The Future of PHP: Adaptations and Innovations Apr 11, 2025 am 12:01 AM

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

PHP: Is It Dying or Simply Adapting? PHP: Is It Dying or Simply Adapting? Apr 11, 2025 am 12:13 AM

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

See all articles