如何利用linux开启远程连接mysql数据库

237 0
2019-7-13 15:26:13
显示全部楼层

1.利用linux命令快速登录到linux下面mysql数据库,对数据库进行操作。

[root@izj6c3z6cxj72ony47na7rz bin]# mysql -uroot -p

Enter password: #此处输入密码

2.修改权限实现远程连接操作

UPDATE user SET host='%' WHERE user='root';

修改之后为了使得权限生效 就必须要刷新权限(flush privileges)

mysql> flush privileges

  -> ;

Query OK, 0 rows affected (0.00 sec)

[color=rgba(0, 0, 0, 0.56)]

[color=rgba(0, 0, 0, 0.56)]3.测试是否连接操作成功

[color=rgba(0, 0, 0, 0.56)]<?php
$dbhost = "";
$dbuser = "root";
$dbpwd = "";
$dbname = "";
$charName = "'UTF8'"; //设置查询字符集gbk,gbk2312,utf-8
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbname);
if (mysqli_connect_errno()) { //注意mysqli_connect_error()新特性
    die('Unable to connect!') . mysqli_connect_error();
}
$sql = "select * from zl_admin";
$rs = $mysqli->query($sql);
$row = $rs->fetch_array();
var_dump($row);
exit;
?>

[color=rgba(0, 0, 0, 0.56)]