How to access MySQL remote database from command line?

How to access MySQL remote database from command line?

Let's say you have a remote server. You want to access the database from your local machine's command line. You can use the below command to directly login to a remote MySQL console.

mysql -u {username} -p'{password}' -h {hostip} -P {port} -D {database}        

-u = User name for login

-p = Password for login

-h = Host Server IP

-P = Port of the remote server

-D = Database you want to connect

* Please don't give space between -p'{password}'

Example:

mysql -u db_admin -p'pass123456' -h 127.0.0.1 -P 3306 -D testdb        

On the other hand, If you're already logged in to your server then only username and password will be sufficient if the database is inside of it.

mysql -u {username} -p        

In this case no database selected. You can check the database list by writing this command.

show databases;        

Now use the command below to access a specific database

use {database};        

or you directly access the database after login,

mysql -u {username} -p -D {database}        

Happy Coding!

#softwaredevelopment?#softwareengineering?#mysql?#remoteaccess?#coding?#programming?#technology?#beginners



Thanks for reading my article.?Please like and share this article if you think it can help others as well. Also comment on what's your impression about it.



You can find me:

Facebook: Code With Rubab

Medium

Dev.to


要查看或添加评论,请登录

Imran Hossain (Rubab)的更多文章

  • Create a Multi Language Based Website With Laravel

    Create a Multi Language Based Website With Laravel

    This article goes in detailed on how to make a website multilingual in Laravel. Users will be able to set the language…

  • Updating Dependency of a Class in Laravel

    Updating Dependency of a Class in Laravel

    If you have already added dependeny Injection in you Constructor method of a class but need to update the dependency…

  • Importance Of Using Log in Your Project

    Importance Of Using Log in Your Project

    As a developer you should write Log in your project. It plays a very important role in your application.

社区洞察

其他会员也浏览了