How to connect to a MySQL database

MySQL
Setup to connect locally
create user [email protected] identified by ‘secret password’;
create database thor character set utf8;
grant all on thor.* to [email protected];

select User,Host from mysql.user;
SHOW GRANTS;
SHOW GRANTS FOR CURRENT_USER;

Setup to connect remotely
mysql> GRANT ALL ON fooDatabase.* TO [email protected]’1.2.3.4′ IDENTIFIED BY ‘my_password’;

This statement will grant ALL permissions to the newly created user fooUser with a password of ‘my_password’ when they connect from the IP address 1.2.3.4.

Testing Remotely
Now you can test your connection remotely. You can access your MySQL server from another Linux server:

# mysql -u fooUser -p -h 44.55.66.77
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.0.45 Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> _

Leave a Reply

Your email address will not be published. Required fields are marked *