Home > Database > Mysql Tutorial > body text

Ubuntu下远程访问MySQL数据库_MySQL

WBOY
Release: 2016-06-01 13:44:26
Original
981 people have browsed it

Ubuntu

bitsCN.com

 

MySQL远程访问的命令

格式:mysql -h主机地址-u用户名 -p用户密码

 

示例:

yanggang@host:~$ mysql -h192.168.1.11 -uroot -p123456

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.11' (111)

出现错误!无法连接远程的MySQL数据库

 

MySQL远程连接数据库,有两种方式:

mysql.sock和TCP/IP,前者比后者连接访问速度更快,但仅限于同一台本机,详见

上述错误,是没有远程访问权限导致的

 

解决方法:

 

1  在目标服务器上(192.168.1.11),修改mysql的my.cnf文件:

sudo vi /etc/mysql/my.cnf

 

2  注释掉bind-address,屏蔽其只对本地监听

#bind-address        = 127.0.0.1

 

3  启动MySQL服务,使其修改的配置生效,详见

sudo restart mysql

配置完了服务器的数据访问权限,此时还是不能远程访问MySQL数据库

这是因为现在还没有对服务器上的数据库或表赋予访问权限(GRANT)

 

4  在服务器上,登录MySQL数据库

mysql -u root -p123456

 

5  对数据库top800赋予权限

grant all privileges on top800.* to root@192.168.1.22 identified by '123456';

flush privileges;

 

6  现在可以远程访问服务器上的MySQL

mysql -h192.168.1.11 -uroot -p123456

/

 

默认,只能访问information_schema和top800,其中top800是我们在步骤5赋予权限的数据库

 

 

知识拓展:

 

1  在服务器上删除用户对数据库的访问权限:

revoke all privileges on top800.* from root@192.168.1.22 identified by '123456';

 

2  在服务器上删除用户root:

delete from user where user='yanggang';

 

3  在修改生效:

flush privileges;

 

4  在服务器上查询用户:

 

/

 

摘自Sunboy_2050的专栏

bitsCN.com
Related labels:
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!