Situation 1: Two libraries are on the same physical host
Joint query (two different libraries, myemployees library and shoppingCart library), these two libraries are on the same On each physical host, they are all on my local machine.
#联合查询(不同的2个库,myemployees库和shoppingCart库) SELECT emp01.`employee_id`, emp01.`first_name` FROM myemployees.employees AS emp01 LIMIT 0, 5 UNION SELECT emp02.`employee_id`, emp02.`first_name` FROM shoppingCart.`employees2` AS emp02; # SELECT emp01.`employee_id`, emp01.`first_name` FROM myemployees.employees AS emp01 LIMIT 0, 5 UNION ALL SELECT emp02.`employee_id`, emp02.`first_name` FROM shoppingCart.`employees2` AS emp02;
Scenario 2: The two libraries are not on the same physical host (that is, the two libraries are on different physical hosts)
In order to demonstrate the effect, I am here Using my virtual machine, I installed the Linux system (centos) in the virtual machine. The MySql database has been installed in the Linux system, the MySql database service has been started, and all the environments have been taken care of.
The ip of my Linux system (centos) is 192.168.117.66.
CREATE TABLE IF NOT EXISTS `user` ( `id` INT(11) DEFAULT NULL, `name` VARCHAR(20) DEFAULT NULL )this code to my local database, and
Add
ENGINE =FEDERATED CONNECTION='mysql://root:root@192.168.117.66:3306/testDB/user';这句话。
CREATE TABLE IF NOT EXISTS `user` ( `id` INT(11) DEFAULT NULL, `name` VARCHAR(20) DEFAULT NULL )ENGINE =FEDERATED CONNECTION='mysql://root:root@192.168.117.66:3306/testDB/user';
at the end. In fact, the above statement, to put it bluntly, is to create a remote database connection in my local database. The shortcut (remote database connection shortcut), what is it similar to? It is similar to the desktop shortcut on the desktop in our window operating system. We can open a certain software icon on the desktop by double-clicking the software icon. It is the same principle.
Just execute the above statement.
By the way, there is one more thing to note:
You need to check whether theFEDERATED engine of your local mysql database has Not turned on.
SHOW ENGINES;If FEDERATED is NO, it means it is not enabled and you need to modify the configuration file of the mysql database.
federated at the end of the configuration file, as shown below:
If you are windows If you are using a Linux system, modify themy.ini file. If you are using a Linux system, modify the my.cnf file.
#After modifying the configuration file, remember to restart the mysql service.
linux restarts the mysql service, service mysqld restart.
Windows restart the mysql service. In the dos window, enter net stop mysql service name, and then enter net start mysql service name.
OK, after everything is done, execute the following sql statement to see the query results of the cross-database query.# SELECT id, aname FROM author UNION SELECT id, `name` FROM `user`;
SELECT * FROM author INNER JOIN `user`;
For the above cross-server and cross-database queries, you need to pay attention to the following points:
1. This cross-database query method does not support transactions, so it is best not to use transactions. 2. The table structure cannot be modified. 3.MySQL uses this cross-database query method. The remote database currently only supports MySQL and other databases do not support it. 4. The table structure must be completely consistent with the target database table.The above is the detailed content of How to implement mysql remote cross-database joint query. For more information, please follow other related articles on the PHP Chinese website!

MySQLdiffersfromotherSQLdialectsinsyntaxforLIMIT,auto-increment,stringcomparison,subqueries,andperformanceanalysis.1)MySQLusesLIMIT,whileSQLServerusesTOPandOracleusesROWNUM.2)MySQL'sAUTO_INCREMENTcontrastswithPostgreSQL'sSERIALandOracle'ssequenceandt

MySQL partitioning improves performance and simplifies maintenance. 1) Divide large tables into small pieces by specific criteria (such as date ranges), 2) physically divide data into independent files, 3) MySQL can focus on related partitions when querying, 4) Query optimizer can skip unrelated partitions, 5) Choosing the right partition strategy and maintaining it regularly is key.

How to grant and revoke permissions in MySQL? 1. Use the GRANT statement to grant permissions, such as GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host'; 2. Use the REVOKE statement to revoke permissions, such as REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host' to ensure timely communication of permission changes.

InnoDB is suitable for applications that require transaction support and high concurrency, while MyISAM is suitable for applications that require more reads and less writes. 1.InnoDB supports transaction and bank-level locks, suitable for e-commerce and banking systems. 2.MyISAM provides fast read and indexing, suitable for blogging and content management systems.

There are four main JOIN types in MySQL: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN returns all rows in the two tables that meet the JOIN conditions. 2.LEFTJOIN returns all rows in the left table, even if there are no matching rows in the right table. 3. RIGHTJOIN is contrary to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet JOIN conditions.

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.


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

Dreamweaver Mac version
Visual web development tools

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
