Home > Database > Mysql Tutorial > body text

在Linux下实现Mysql远程访问

WBOY
Release: 2016-06-07 16:34:26
Original
1027 people have browsed it

步骤一 激活Mysql配置文件my.cnf中的远程访问 位置: /etc/mysql/my.cnf (Debian linux) /etc/my.cnf (Red Hat Linux/Fedora Linux) /var/db/mysql/my.cnf (FreeBSD) 用VI打开,查找到bind-address这项,默认情况是127.0.0.1 把他注释掉,或者改成数据库主

步骤一 激活Mysql配置文件my.cnf中的远程访问

位置:

/etc/mysql/my.cnf (Debian linux)
/etc/my.cnf (Red Hat Linux/Fedora Linux)
/var/db/mysql/my.cnf (FreeBSD)

用VI打开,查找到bind-address这项,默认情况是127.0.0.1
把他注释掉,或者改成数据库主机所在IP地址。
比如?bind-address = 65.212.65.12

步骤二 授权帐户具有远程访问属性

首先登陆在数据库所在Linux上用Root权限登陆Mysql。

use mysql;
select host, user from mysql;
Copy after login

正常情况下是只有三个root用户,他们的host分别是

  • 127.0.0.1
  • ::1
  • localhost

如果我们其中127.0.0.1改为我们所需要的ip地址,比如:218.51.21.21,那么用这台IP的机子就能实现远程登陆mysql进行管理。这里要用到用户授权的语法。

grant all on *.* to username@’ip’ identified by “password”;

由此我们就可以新建一个超级管理员的帐户:

mysql > grant all privileges on *.* to admin@localhost identified by '123456' with grant option;
mysql > grant all privileges on *.* to admin@'%' identified by '123456' with grant option;
Copy after login

其中第二句中’%'表示通配符,任何IP都能通过admin帐户远程访问mysql。
建立好之后我们再看看

select host, user from user;
Copy after login

是不是发现有两个新的用户名是admin,这时我们就可以开启远程访问了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!