Access mysql remote database from command line

2019-01-10 03:14发布

I have a server with Rackspace. I want to access the database from my local machine command line.

I tried like:

mysql -u username -h my.application.com -ppassword

But it gives an error:

ERROR 2003 (HY000):

Can't connect to MySQL server on 'my.application.com' (10061)

What causes this error and how can I connect to the remote database?

13条回答
Bombasti
2楼-- · 2019-01-10 03:51

I was too getting the same error. But found it useful by creating new mysql user on remote mysql server ans then connect. Run following command on remote server:

CREATE USER 'openvani'@'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'@'localhost WITH GRANT 
OPTION;
CREATE USER 'openvani'@'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Now you can connect with remote mysql with following command.

mysql -u openvani -h 'any ip address'-p

Here is the full post:

http://openvani.com/blog/connect-remotely-mysql-server/

查看更多
时光不老,我们不散
3楼-- · 2019-01-10 03:52

For Mac, use the following command:

mysql -u app -h hostaddress -P port -D dbname -p

and then enter the password when prompted.

查看更多
虎瘦雄心在
4楼-- · 2019-01-10 04:02

Try this command mysql -uuser -hhostname -PPORT -ppassword.

I faced a similar situation and later when mysql port for host was entered with the command, it was solved.

查看更多
趁早两清
5楼-- · 2019-01-10 04:03

simply put this on terminal at ubuntu:

mysql -u username -h host -p

Now hit enter

terminal will ask you password, enter the password and you are into database server

查看更多
我只想做你的唯一
6楼-- · 2019-01-10 04:03

I assume you have MySQL installed on your machine. Execute the command below after filling missing details:

mysql -uUSERNAME -pPASSWORD -hHOSTNAME -P3306 
查看更多
走好不送
7楼-- · 2019-01-10 04:03

You should put your password with 'p'

mysql -u root -u 1.1.1.1 -p'MyPass'
查看更多
登录 后发表回答