[英]mysql access denied, ssh database host
i am trying to access mysql into an remote server, and create a database there. 我正在尝试将mysql访问到远程服务器中,并在那里创建数据库。 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) 错误1045(28000):拒绝访问用户'username'@'localhost'(使用密码:NO)
ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES) 错误1045(28000):用户'username'@'localhost'的访问被拒绝(使用密码:是)
one for each occasion, when i do not enter a password, and when i do. 当我不输入密码时和每次输入密码时,请分别使用一种。
You are having issues with remote access to MySql. 您在远程访问MySql时遇到问题。 From here 从这里
First, login over ssh to remote MySQL database server 首先,通过ssh登录到远程MySQL数据库服务器
Once connected you need edit the mysql configuration file my.cfg using text editor such as vi. 连接后,您需要使用文本编辑器(如vi)编辑mysql配置文件my.cfg。
In Debian Linux file is located at /etc/mysql/my.cnf
在Debian Linux中,文件位于/etc/mysql/my.cnf
# vi /etc/my.cnf
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: 例如,如果您的MySQL服务器IP为172.20.5.2,则整个块应如下所示:
[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. 其中-bind-address:要绑定的IP地址。 - skip-networking : Don't listen for TCP/IP connections at all. -跳过网络:完全不监听TCP / IP连接。 All interaction with mysqld must be made via Unix sockets. 与mysqld的所有交互都必须通过Unix套接字进行。 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. 由于您需要允许远程连接,因此应从文件中删除此行或将其置于注释状态。
Restart your mysql service to take change in effect 重新启动mysql服务以使更改生效
# /etc/init.d/mysql restart
Step # 5 Grant access to remote IP address 步骤5授予对远程IP地址的访问权限
# mysql -u root –p mysql #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: 如果要为用户栏和远程IP 162.54.10.20添加名为foo的新数据库,则需要在mysql>提示符下键入以下命令:
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. 让我们假设您始终与用户Webadmin的名为webdb的数据库的远程IP(称为162.54.10.20)建立连接,那么您需要授予对该IP地址的访问权限。 At mysql> prompt type following command for existing database: 在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';
Type exit command to logout mysql 键入exit命令以注销mysql
mysql> exit
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连接到端口3306以进行测试
$ telnet 172.20.5.2 3306
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.