linux为啥不允许远程连接mysql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux为啥不允许远程连接mysql相关的知识,希望对你有一定的参考价值。

首先linux是开源的操作系统,在安全性的级别上面是非常高的,多种机制
共同保证
安全。linux上面安装mysql,其中mysql的用户表中有几个要素:用户名,密码,远程主机IP。其中在linux中127.0.0.1

localhost

在表现上不是一个主机。默认是本机可以连接,如果需要
远程连接
的话,需要进行数据授权。
[root@linuxprobe
~]#grant
【权限】
to数据库
用户名@主机ip
identified

by
'密码';
这个是用户的授权,只用授权了ip才能用哪个IP来访问。linux更多知识
建议参考《linux就该这样学》看看。要注意安全性,在设置授权时候要谨慎,希望能够帮助到你
参考技术A 1、root用户登录到mysql数据库
代码示例:
/usr/local/mysql/bin/mysql
-u
root
-p
(输入密码进入mysql)
2、进入mysql,输入:
代码示例:
use
mysql;
3、查看user表的情况
代码示例:
select
host,user
from
user;
//指明主机名称,“%”表示匹配所有字符串
4、
代码示例:
update
user
set
host
=
'%'
where
user=
'root'
limit
1;
5、输入如下命令让刚才设置的命令生效
代码示例:
mysql>
flush
privileges;
query
ok,
0
rows
affected
(0.00
sec)
注意,在mysql
命令行形式下一定要输入";"
按照前面五个步骤完成之后,通过控制台输入:
代码示例:
[root@linux
~]#
mysql
-h
localhost
-u
root
-p
enter
password:
error
1045
(28000):
access
denied
for
user
'root'@'localhost'
(using
password:
yes)
不让这么连接数据库
原因:是因为host对应的user字段是空的,我们需要将其改为root即可
代码示例:
mysql>
select
host,user
from
user;
+-----------+------+
|
host
|
user
|
+-----------+------+
|
%
|
root
|
|
127.0.0.1
|
root
|
|
linux
|
|
|
linux
|
root
|
|
localhost
|
|
+-----------+------+
5
rows
in
set
(0.00
sec)
解决办法一:
代码示例:
mysql>
update
user
set
user='root'
where
host='localhost';
query
ok,
1
row
affected
(0.00
sec)
rows
matched:
1
changed:
1
warnings:
0
mysql>
flush
privileges;
query
ok,
0
rows
affected
(0.00
sec)
解决办法二:
将localhost改为本机的ip地址,则能够识别了。
代码示例:
[root@linux
~]#
mysql
-h
172.16.42.68
-u
root
-p
enter
password:
welcome
to
the
mysql
monitor.
commands
end
with
;
or
\g.
your
mysql
connection
id
is
157
server
version:
5.1.66
source
distribution
copyright
(c)
2000,
2012,
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.

Linux下mysql允许远程连接怎么设置

参考技术A 您好!
1、首先,mysql设置远程连接的方式是在linux中进入mysql
mysql -uroot -pxxxxx(该处为root密码)
2、进入mysql后进行权限授权
grant all privileges on *.* to root@'%' identified by "xxxxxx" with grant option;
flush privileges;
这样就可以远程连接mysql了,其中第二部中的xxxxxx为密码您可以自行修改。本回答被提问者和网友采纳

以上是关于linux为啥不允许远程连接mysql的主要内容,如果未能解决你的问题,请参考以下文章

Linux 如何开启MySQL远程访问权限 允许远程连接

超级详细教程03:允许远程连接Mysql数据库(Linux系统+Windows系统)

超级详细教程03:允许远程连接Mysql数据库(Linux系统+Windows系统)

linux下mysql允许远程连接

电脑上怎么建立远程桌面连接为啥总是不成功

Linux下mysql允许远程连接怎么设置