4.2.5. MySQL connection

发布时间 : 2025-10-25 13:32:48 UTC      

Page Views: 9 views

Connect using mysql binary

You can use MySQL binary to enter the mysql command prompt to connect to the MySQL database.

Example

The following is a simple example of connecting to a mysql server from the command line:

[root@host]# mysql -u root -p Enter password:****** 

After a successful login, a mysql > command prompt window appears, on which you can execute any SQL statement.

After the above command is executed, the successful login output is as follows:

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2854760 to server version: 5.0.9 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 

In the above example, we use root users to log in to the mysql server, but you can also log in with other mysql users.

If the user permissions are sufficient, any user can SQL from the command prompt window of mysql.

You can use the exit command to exit the mysql > command prompt window, as follows:

mysql> exit Bye 

Connect to MySQL using a PHP script

PHP provides mysqli_connect() Function to connect to the database.

This function takes six parameters, returns the connection ID after a successful link to MySQL, and returns FALSE if it fails.

Grammar

mysqli_connect(host, username, password, dbname,port, socket); 

参数说明:

Parameters.

Description

host

Optional. Specify the hostname or IP address.

username

Optional. Specifies the MySQL user name.

password

Optional. Specify the MySQL password.

dbname

Optional. Specify the database to use by default.

port

Optional. Specifies the port number that attempts to connect to the MySQL server.

socket

Optional. Specifies the socket or named pipe to use.

You can use PHP. mysqli_close() Function to break the link to the MySQL database.

Only one argument to this function is mysqli_connect() The MySQL connection identifier returned after the function successfully created the connection.

Grammar

bool mysqli_close ( mysqli $link ) 

This function closes the non-persistent connection to the MySQL server associated with the specified connection identity. If not specified link_identifier Closes the last open connection

提示: There is usually no need to use the mysqli_close() Because open non-persistent connections are automatically closed after the script is executed

Example

You can try the following example to connect to your MySQL server:

Connect MySQL

 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。