MySQL - DROP SERVER Statement



MySQL DROP SERVER Statement

If you need to use either of the Spider, FEDERATED or FederatedX storage engines. You need to create a server.

You can create a server using the CREATE SERVER statement. This statement creates a new row in the servers table in the mysql database.

Syntax

Following is the syntax of the DELETE SERVER statement −

DROP SERVER server_name

Example

Assume we have created two servers using the CREATE SERVER statement as shown below −

CREATE SERVER myserver FOREIGN DATA WRAPPER mysql OPTIONS (USER 'Remote', HOST 'localhost', DATABASE 'federated'); CREATE SERVER test FOREIGN DATA WRAPPER mysql OPTIONS (HOST 'localhost');

If you list out the servers in mysql using the SELECT statement you can observe the above created server in it −

SELECT * FROM mysql.servers\G;

Output

The above mysql generates the following output −

*********** 1. row *********** Server_name: myserver Host: localhost Db: federated Username: test Password: Port: 0 Socket: Wrapper: mysql Owner: *********** 2. row *********** Server_name: test Host: localhost Db: Username: Password: Port: 0 Socket: Wrapper: mysql Owner:

Following queries deletes the servers created above −

DROP SERVER myserver; DROP SERVER test;

Verification

If you verify the list of servers again you will get an empty list as shown below −

SELECT * FROM mysql.servers; Empty set (0.00 sec)

The IF EXISTS clause

If you try to drop a server that doesnt exist, an error will be generated as shown below −

DROP server demo; ERROR 1477 (HY000): The foreign server name you are trying to reference does not exist. Data source error: demo

If you use the IF EXISTS clause along with the DROP SERVER statement as shown below, the specified server will be dropped and if a server with the given name, doesnt exist the query will be ignored.

DROP SERVER IF EXISTS demo;
mysql_statements_reference.htm
Advertisements