Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL connection

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MySQL connection uses mysql binary connection

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-pEnter 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.9Type '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 > exitBye uses PHP script to connect to MySQL

PHP provides the 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.

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

Parameter description:

Parameter description host is optional. Specify the hostname or IP address. Username is optional. Specifies the MySQL user name. Password is optional. Specify the MySQL password. Dbname is optional. Specify the database to use by default. Port is optional. Specifies the port number that attempts to connect to the MySQL server. Socket is optional. Specifies the socket or named pipe to use.

You can use the mysqli_close () function of PHP to disconnect from the MySQL database.

This function has only one argument to the MySQL connection identifier returned by the mysqli_connect () function after a successful connection is created.

Syntax bool mysqli_close (mysqli $link)

This function closes the non-persistent connection to the MySQL server associated with the specified connection identity. If no link_identifier is specified, the last open connection is closed.

Tip: you don't usually need to use 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report