DBA:多连接MySQL
2018-08-27 21:47
316 查看
一、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);
参数说明:
注意:想要断开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.
2.
相关文章推荐
- jdbc连接mysql的方法
- C#连接Mysql之MySQLDriverCS
- 解决Python2.7 连接MySQL数据库遇到'can't connect to MySQL server on 'localhost'(10061)'问题
- mysql连接数据库函数内存泄露解决方案
- 连接linux的MySQL服务报表不存在的错误问题
- .net 连接MySql
- mysql用户连接数
- .Net+Mysql中的数据库连接
- 局域网内mysql连接慢的解决办法
- mysql重连,连接丢失:The last packet successfully received
- MySQL内外连接
- R语言连接MYSQL
- mysql能用localhost连接不能使用127.0.0.1连接的解决办法
- VB6.0连接MySQL数据库
- Mysql中两个字段连接成一个子段
- 如果你修改了MYSQL的data默认位置在命令行连接时会有问题
- 初学者使用hibernate连接MySQL出现unable to create connection check your url问题
- 浅析node连接数据库(express+mysql)
- servlet学习笔记之七(连接mysql)
- 开放远程连接mysql