Accessing MySQL from the Command Line Print

  • 2


Accessing MySQL from the Command Line

Direct connection

To connect to a MySQL database via terminal, use the following syntax:

mysql -h HOST -u USERNAME -pPASSWORD

 


Enable Remote Access to MySQL

Configuration change

To allow MySQL access from external hosts (not just localhost), edit the following file:

/etc/mysql/my.cnf

Find the bind-address directive and set it to:

bind-address = 0.0.0.0

 

Grant user access from any IP

Run this MySQL command to allow a user to connect from any host:

GRANT ALL ON *.* TO 'user'@'%' IDENTIFIED BY 'password';

Then apply the changes with:

FLUSH PRIVILEGES;

 

Restart the MySQL service

To apply all changes, restart the service:

service mysqld restart

 


Was this answer helpful?

« Back