mysql 访问被拒绝,ssh 数据库主机

发布于 2024-10-20 00:08:04 字数 352 浏览 6 评论 0原文

我正在尝试访问 mysql 到远程服务器,并在那里创建一个数据库。 我正在使用腻子进行连接。问题是我收到“访问被拒绝”错误 无论我做什么:

:mysql -p
:mysql -u <username> -p
.
.
.

我仍然收到警告。

错误 1045 (28000):用户“用户名”@“localhost”的访问被拒绝(使用密码:NO)

错误 1045 (28000):用户“用户名”@“localhost”的访问被拒绝(使用密码:YES)

每种情况一个,当我不输入密码时,以及当我输入密码时。

i am trying to access mysql into an remote server, and create a database there.
i am using putty to connect. the problem is that i get the "access denied" error
whatever i do:

:mysql -p
:mysql -u <username> -p
.
.
.

i still get the warning.

ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: NO)

ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES)

one for each occasion, when i do not enter a password, and when i do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老街孤人 2024-10-27 00:08:04

您在远程访问 MySql 时遇到问题。从此处

  • 步骤#1:通过 ssh 登录

首先,通过 ssh 登录到远程 MySQL 数据库服务器

  • 步骤#2:启用网络

连接后,您需要使用文本编辑器(例如vi)编辑mysql配置文件my.cfg。

在 Debian Linux 中,文件位于 /etc/mysql/my.cnf

# vi /etc/my.cnf
  • 第 3 步:文件打开后,找到显示为 [mysqld] 的行

确保注释了跳过网络行(或删除行)并添加以下行

bind-address=YOUR-SERVER-IP

,则整个块应如下所示:

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 172.20.5.2

# skip-networking
....
..
....

例如,如果您的 MySQL 服务器 IP 是172.20.5.2
- 绑定地址:要绑定的IP地址。
-skip-networking :根本不监听 TCP/IP 连接。所有与 mysqld 的交互都必须通过 Unix 套接字进行。对于仅允许本地请求的系统,强烈建议使用此选项。由于您需要允许远程连接,因此应从文件中删除此行或将其置于注释状态。

  • 步骤#4 保存并关闭文件。

重新启动 mysql 服务以使更改生效

# /etc/init.d/mysql restart
  • 第 5 步授予对远程 IP 地址的访问权限

    # mysql -u root –p mysql

授予对新 IP 地址的访问权限数据库

如果你想为用户 bar 添加名为 foo 的新数据库,远程 IP 为 162.54.10.20,那么你需要在 mysql> 中键入以下命令:提示:

mysql> CREATE DATABASE foo;

mysql> GRANT ALL ON foo.* TO bar@'162.54.10.20' IDENTIFIED BY 'PASSWORD';

授予对现有数据库的访问权限

让我们假设您始终从名为 162.54.10.20 的远程 IP 与用户 webadmin 的名为 webdb 的数据库建立连接,那么您需要授予对此 IP 地址的访问权限。在mysql>提示符为现有数据库键入以下命令:

mysql> update db set Host='162.54.10.20' where Db='webdb';

mysql> update user set Host='162.54.10.20' where user='webadmin';
  • 步骤#6:注销 MySQL

键入 exit 命令以注销 mysql

mysql> exit
  • 进行测试

步骤#7:从远程系统键入命令

$ mysql -u webadmin –h 172.20.5.2 –p

您还可以使用 telnet 连接到端口 3306 进行测试

$ telnet 172.20.5.2 3306

You are having issues with remote access to MySql. From here

  • Step # 1: Login over ssh

First, login over ssh to remote MySQL database server

  • Step # 2: Enable networking

Once connected you need edit the mysql configuration file my.cfg using text editor such as vi.

In Debian Linux file is located at /etc/mysql/my.cnf

# vi /etc/my.cnf
  • Step # 3: Once file open, locate line that read as [mysqld]

Make sure line skip-networking is commented (or remove line) and add following line

bind-address=YOUR-SERVER-IP

For example, if your MySQL server IP is 172.20.5.2 then entire block should be look like as follows:

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 172.20.5.2

# skip-networking
....
..
....

Where
- bind-address : IP address to bind to.
- skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should removed from file or put it in comment state.

  • Step# 4 Save and Close the file.

Restart your mysql service to take change in effect

# /etc/init.d/mysql restart
  • Step # 5 Grant access to remote IP address

    # mysql -u root –p mysql

Grant access to new database

If you want to add new database called foo for user bar and remote IP 162.54.10.20 then you need to type following commands at mysql> prompt:

mysql> CREATE DATABASE foo;

mysql> GRANT ALL ON foo.* TO bar@'162.54.10.20' IDENTIFIED BY 'PASSWORD';

Grant access to existing database

Let us assume that you are always making connection from remote IP called 162.54.10.20 for database called webdb for user webadmin then you need to grant access to this IP address. At mysql> prompt type following command for existing database:

mysql> update db set Host='162.54.10.20' where Db='webdb';

mysql> update user set Host='162.54.10.20' where user='webadmin';
  • Step # 6: Logout of MySQL

Type exit command to logout mysql

mysql> exit
  • Step # 7: Test it

From remote system type command

$ mysql -u webadmin –h 172.20.5.2 –p

You can also use telnet to connect to port 3306 for testing purpose

$ telnet 172.20.5.2 3306
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文