mysql 数据库设计_MySQL
bitsCN.com
innodb表正好相反;行级锁表
互联网服务,不算支付性的服务外,互动产品,新闻系统等等一般都是读多,写少。用myisam表比较合适。
表的设计
定长表:所有列的字段长度都是定长的。可以去查mysql的手册不定长字段是VARCHAR、BLOB或TEXT。int char都是定长的,定长表占用空间会大。
动态表:就是字段不是都定长的。
定长表要比动态表检索速度快。
软件系统的设计习惯是把每张表都分清很明确的功能,比如用户表都是用户信息,如果需要同时从留言表取数据,又从用户表取用户信息的时候,就会采用联合查 询,有的时候一些操作还会用left,join等各种复杂sql语句,没准还要用mysql的函数。如果是针对访问量,读取量很大的互联网服务时,同时并 发去读,数据量又大,很可怕。最好是如果数据不会修改,在常用的表上有冗余字段,能够做到一次读,把数据都拿到;可以有冗余的写操作,但减少复杂的查询操 作。
在设计表的时候要将这个表的所有字段类型占用的字节数求和,并乘以你的预期(如:存储100W数据量),就是整张表未来会占用容量。
拆表 拆库
拆表就是将一张表复制N多张,里面分别存放不用内容的数据,数据的存放是用HASH算法来决定放入哪张表。
例如用户表user,传统情况就是一张表,拆表就是将表复制为user_01,user_02等里面都存放了格式一样的不同用户数据。
拆库和拆表类似,就是库的复制。
拆表或拆库有很多的HASH算法,主要目的就是减少表的数据量,用算法保证每个表的数据量平均,请求,读写操作被分摊降低压力,而且安全,出了问题最多是一部分用户受影响。缺点就是检索不方便,需要另想办法。
很多网站为了前期省事都会采用discuz的产品,如bbs,blog等,网上有不少关于这个产品的介绍和优化方法,没细研究过,听过一些网站介绍他们的 优化方法时,对于数据库主要是采用主从的方法,将数据库的读写分离来提高性能,但是个人觉得这种办法在数据量到了规模的时候就OVER了,并发和读写操作 没提升,数据也是会逐渐累计超过限制。
互联网服务由于要应对大数据量,大请求量,所以在设计开发的时候就不要太学院派,不要力图达到数据库、程序的设计“优美”,性能是最要紧的。bitsCN.com

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

AI Hentai Generator
Generate AI Hentai for free.

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



Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

PHP provides the following methods to delete data in MySQL tables: DELETE statement: used to delete rows matching conditions from the table. TRUNCATETABLE statement: used to clear all data in the table, including auto-incremented IDs. Practical case: You can delete users from the database using HTML forms and PHP code. The form submits the user ID, and the PHP code uses the DELETE statement to delete the record matching the ID from the users table.
