Start a connection using MySQL binary
you can use MySQL binary to enter the MySQL command prompt to connect to the MySQL database.
Instance
The following is a simple example of connecting to a MySQL server from the command line:
[root@host]# mysql-u Root-p
The mysql> Command Prompt window appears when the login succeeds, and you can execute any SQL statements on it.
After the above command executes, the login success 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 the root user login to the MySQL server, of course, you can also use other MySQL user login.
If the user has sufficient permissions, any user can perform SQL operations in the MySQL Command Prompt window.
You can exit the mysql> Command Prompt window by using the Exit command, as follows:
use PHP script to connect to MySQL
PHP provides the mysql_connect () function to connect to the database.
The function has 5 parameters that return the connection identity after the successful link to MySQL, and the failure returns FALSE.
Grammar
Connection mysql_connect (Server,user,passwd,new_link,client_flag);
Parameter description:
You can use PHP's Mysql_close () function to disconnect from the MySQL database.
This function has only one parameter for the mysql_connect () function to create the MySQL connection identifier returned after successful connection.
Grammar
BOOL Mysql_close (Resource $link _identifier);
This function closes a non-persistent connection to the MySQL server associated with the specified connection identity. If Link_identifier is not specified, the last open connection is closed.
Tip: You typically do not need to use mysql_close (), because an open non-persistent connection shuts down automatically after the script has finished executing.
Note: mysql_close () does not close persistent connections established by Mysql_pconnect ().
Instance
You can try the following examples to connect to your MySQL server:
PHP calls the MySQL function
MySQL can be applied in a variety of languages, including PERL, C, C + +, JAVA, and PHP. In these languages, MySQL is the most widely used web development in PHP.
Most of our examples in this tutorial are in the PHP language. If you want to know the MySQL application in PHP, you can visit our PHP using MySQL introduction.
PHP provides a variety of ways to access and manipulate MySQL database records. PHP MySQL function format is as follows:
Mysql_function (Value,value,...); The function section of the above format describes the functions of the MySQL function, such as
- Mysqli_connect ($connect);
- Mysqli_query ($connect, "SQL statement");
- Mysql_fetch_array ()
- Mysql_connect (), Mysql_close ()
The following example shows the syntax for invoking a MySQL function in PHP: