Connect to remote MySQL server

家里有两台台式机,一台干脆专门用来下data,配置了一下MySQL,从另一台电脑上成功连接,把大概的步骤记录一下。

  • 打开 3306 端口
    ….MySQL的默认端口是3306,需要配置firewall来开放端口,如果是Windows机可以参考这篇文章

  • 建立远程连接的用户
    …. 添加用户

    1
    2
    CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
    CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';

    ….设定用户的权限

    1
    2
    GRANT ALL ON *.* TO 'myuser'@'localhost';
    GRANT ALL ON *.* TO 'myuser'@'%';
  • 连接

    1
    mysql -u USERNAME -h HOST_IP -p
  • 基本操作

    1
    2
    3
    4
    5
    6
    // Show all databases
    show database;
    // Switch to a table
    use DATABASE_NAMME;
    // Show all tables
    show tables;

Reference:
http://stackoverflow.com/questions/16287559/mysql-adding-user-for-remote-access
http://stackoverflow.com/questions/15872543/access-remote-database-from-command-line