DBA:多连接MySQL
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DBA:多连接MySQL相关的知识,希望对你有一定的参考价值。
一、mysql二进制连接
使用MySQL二进制方式进入到mysql命令提示符下连接MySQL数据库。
实例操作:
[[email protected] ~]# 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
[[email protected] ~]#
二、php脚本连接MySQL
PHP提供了mysqli_connect()函数来连接数据库
该函数一共有6个参数,在成功连接到MySQL后返回连接标识,失败返回false语法:
mysqli_connect(host,username,password,dbname,port,socket);
参数说明:
注意:想要断开MySQL连接可以使用mysqliclose()函数来断开与MySQL服务器的连接,该函数只有一个参数为mysqliconnect()函数创建连接成功后返回的MySQL连接标识符。
语法:
bool mysqli_close(mysqli $link)
本函数关闭指定的连接标识所关联到的MySQL服务器的非持久连接。如果没有指定linkidentifier,则关闭上一个打开的连接。通常不需要使用mysqliclose(),因为打开的非持久连接会在脚本执行完毕后自动关闭。
实例操作:
[[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]#
网页访问:
1.
2.
以上是关于DBA:多连接MySQL的主要内容,如果未能解决你的问题,请参考以下文章
连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段
Mysql DBA 高级运维学习笔记-MySQL数据库多实例介绍