I'm taking a shot at an SQL application in java, and I have "set up" a mysql server on 192.168.1.123 on my network.
Here's what I did to install it on Ubuntu:
sudo apt-get update sudo apt-get install mysql-server mysqladmin -u root -p create vtDB mysql -u -root -p mysql >INSERT INTO user (Host, User, Password, Select_priv) VALUES ('%', 'user', password('password'), 'Y'); >FLUSH PRIVILEGES; >GRAND ALL PRIVILEGES ON vtDB.* TO 'user'@'%'; >FLUSH PRIVILEGES; >exit mysqladmin -u root -p reload
Here's the code that I am trying to use, it's all hard coded atm as I'm in the testing stage:
try { System.out.println("Attempting to load JDBC Driver: com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println("Driver Loaded, attempting connection"); String url = "jdbc:mysql://192.168.1.123:3306/"; Connection con = DriverManager.getConnection(url, "user", "password); Statement s = con.createStatement(); s.executeQuery("CREATE TABLE 2_29 (Standard VARCHAR(100), Unit VARCHAR(100), Topic VARCHAR(100), Level VARCHAR(100), Methods VARCHAR(500), Spiritual VARCHAR(500), Academic VARCHAR(500), Artistic VARCHAR(500), Athletic VARCHAR(500), Service VARCHAR(500), i_GRADE INT, i_UNIT INT, i_TOPIC VARCHAR(100), m_GRADE INT, m_UNIT INT, m_TOPIC VARCHAR(100), r_GRADE INT, r_UNIT INT, r_TOPIC VARCHAR(100), LASTMOD TIMESTAMP(8)) TYPE=innodb"); System.out.println("Table Created"); } catch (ClassNotFoundException cnfe) // driver not found { cnfe.printStackTrace(); System.err.println ("Unable to load database driver"); System.exit(0); } catch (InstantiationException e) { System.err.println ("Unable to load database driver"); e.printStackTrace(); } catch (IllegalAccessException e) { System.err.println ("Unable to load database driver"); e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }
Here's the full error:
java.sql.SQLException: Access denied for user 'user'@'192.168.1.2' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775) at com.mysql.jdbc.Connection.<init>(Connection.java:1555) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at BasicDatbaseTest.main(BasicDatbaseTest.java:18)
I've tested everything locally, and the user can log in no problem and execute the exact same query.