DBA: Multi-Connection MySQL

Source: Internet
Author: User
Tags dba php script

One, MySQL binary connection

Use the MySQL binary method to access the MySQL database at the MySQL command prompt.

Instance operations:

[[email protected] ~]# mysql -uroot -pEnter password:#登录成功出现以下信息Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 5     #显示你连接服务器的用户IDServer version: 5.7.18-log Source distribution      #服务器的版本信息Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> exit                                    #退出数据库命令Bye[[email protected] ~]#
Second, PHP script connection MySQL

PHP provides the Mysqli_connect () function to connect to the database
This function has a total of 6 parameters, after successfully connected to MySQL return connection identity, failed to return false

Grammar:
Mysqli_connect (Host,username,password,dbname,port,socket);

Parameter description:

Note: To disconnect a MySQL connection, you can use the Mysqliclose () function to disconnect from the MySQL server, which has only one parameter for the Mysqliconnect () function to create a MySQL connection identifier that is returned after a successful connection.

Grammar:
BOOL Mysqli_close (mysqli $link)

This function closes the non-persistent connection to the MySQL server to which the specified connection ID is associated. If Linkidentifier is not specified, the last open connection is closed. Mysqliclose () is not usually required because open non-persistent connections are automatically closed after the script has finished executing.

Instance operations:

[[email protected] web]# cat index.php<?$dbhost = ‘localhost:3306‘;#$dbport = ‘3306‘;$dbuser = ‘root‘;$dbpass = ‘000000‘;$conn = mysqli_connect($dbhost,$dbuser,$dbpass);if ( ! $conn){    die(‘Could not connect:‘. mysqli_error());}echo ‘connect success!!!‘;mysqli_close($conn);?>[[email protected] web]#

Web Access:
1.

2.

DBA: Multi-Connection MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.