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