国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
yii2數(shù)據(jù)庫讀寫分離配置,yii2數(shù)據(jù)庫讀寫
Home php教程 php手冊 yii2數(shù)據(jù)庫讀寫分離配置,yii2數(shù)據(jù)庫讀寫

yii2數(shù)據(jù)庫讀寫分離配置,yii2數(shù)據(jù)庫讀寫

Jul 06, 2016 pm 02:24 PM
yii yii2 separation database Read and write Configuration Link

yii2數(shù)據(jù)庫讀寫分離配置,yii2數(shù)據(jù)庫讀寫

原文鏈接:Yii中文網(wǎng)(yii-china.com)-yii2數(shù)據(jù)庫讀寫分離配置

簡介

數(shù)據(jù)庫讀寫分離是在網(wǎng)站遇到性能瓶頸的時(shí)候最先考慮優(yōu)化的步驟,那么yii2是如何做數(shù)據(jù)庫讀寫分離的呢?本節(jié)教程來給大家普及一下yii2的數(shù)據(jù)庫讀寫分離配置。

兩個(gè)服務(wù)器的數(shù)據(jù)同步是讀寫分離的前提條件,但這不在yii2讀寫分離教程內(nèi),yii2的數(shù)據(jù)庫讀寫分離配置,僅僅實(shí)現(xiàn)了在主庫讀寫,在從庫查詢,那么我們首先要配置主從服務(wù)器的數(shù)據(jù)同步。詳情查看linux數(shù)據(jù)庫主從同步配置

配置

主從服務(wù)器數(shù)據(jù)庫同步完成之后,我們就可以開始yii2的讀寫分離配置,官方也有這方面的文檔,但說的并不清楚,也沒有實(shí)際的例子,醬油君在這里加以完善。

1.打開我們的數(shù)據(jù)庫配置文件common\config\main-local.php在db屬性中做如下配置

'db' => [
    'class' => 'yii\db\Connection',
    
    // 配置主服務(wù)器
    'dsn' => 'mysql:host=192.168.0.1;dbname=hyii2',
    'username' => 'root',
    'password' => 'root',
    'charset' => 'utf8',
    
    // 配置從服務(wù)器
    'slaveConfig' => [
        'username' => 'root',
        'password' => 'root',
        'attributes' => [
            // use a smaller connection timeout
            PDO::ATTR_TIMEOUT => 10,
        ],
        'charset' => 'utf8',
    ],
    
    // 配置從服務(wù)器組
    'slaves' => [
            ['dsn' => 'mysql:host=192.168.0.2;dbname=hyii2'],
        ],
],

如上配置就能實(shí)現(xiàn)yii2數(shù)據(jù)庫讀寫分離的操作,很簡單,只要一個(gè)配置就ok了,讀寫分離的功能由后臺代碼自動完成.調(diào)用者無須關(guān)心。

上面只是一個(gè)1主1從的配置,如果要一主多從,或者多主多從,參考此例以及官方文檔即可完成。

更多關(guān)于yii2的精品文檔點(diǎn)擊此處

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

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.

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL: A Beginner-Friendly Approach to Data Storage MySQL: A Beginner-Friendly Approach to Data Storage Apr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

What is the difference between php framework laravel and yii What is the difference between php framework laravel and yii Apr 30, 2025 pm 02:24 PM

The main differences between Laravel and Yii are design concepts, functional characteristics and usage scenarios. 1.Laravel focuses on the simplicity and pleasure of development, and provides rich functions such as EloquentORM and Artisan tools, suitable for rapid development and beginners. 2.Yii emphasizes performance and efficiency, is suitable for high-load applications, and provides efficient ActiveRecord and cache systems, but has a steep learning curve.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

Real-World MySQL: Examples and Use Cases Real-World MySQL: Examples and Use Cases Apr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

Redis: Understanding Its Architecture and Purpose Redis: Understanding Its Architecture and Purpose Apr 26, 2025 am 12:11 AM

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

See all articles