DBA:多连接MySQL

一、mysql二进制连接

使用MySQL二进制方式进入到mysql命令提示符下连接MySQL数据库。

实例操作:

[root@mysql-linuxview ~]# mysql -uroot -p
Enter password:
#登录成功出现以下信息
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5     #显示你连接服务器的用户ID
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit                                    #退出数据库命令
Bye
[root@mysql-linuxview ~]#

二、PHP脚本连接MySQL

PHP提供了mysqli_connect()函数来连接数据库
该函数一共有6个参数,在成功连接到MySQL后返回连接标识,失败返回false

语法:
mysqli_connect(host,username,password,dbname,port,socket);

参数说明:
DBA:多连接MySQL

注意:想要断开MySQL连接可以使用mysqliclose()函数来断开与MySQL服务器的连接,该函数只有一个参数为mysqliconnect()函数创建连接成功后返回的MySQL连接标识符。

语法:
bool mysqli_close(mysqli $link)

本函数关闭指定的连接标识所关联到的MySQL服务器的非持久连接。如果没有指定linkidentifier,则关闭上一个打开的连接。通常不需要使用mysqliclose(),因为打开的非持久连接会在脚本执行完毕后自动关闭。

实例操作:

[root@mysql-linuxview 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);
?>

[root@mysql-linuxview web]#

网页访问:
1.
DBA:多连接MySQL

2.
DBA:多连接MySQL

转载于:https://blog.51cto.com/leoheng/2165127

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值