Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Local Domain MySQL server, access denied

  1. #1
    Member
    Join Date
    Apr 2011
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Local Domain MySQL server, access denied

    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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Local Domain MySQL server, access denied

    First, can you use JDBC to login as root (this will test whether your computer can actually see the database regardless of the user you created)? Second, I don't recommend inserting directly into the user table. Rather, use the predefined SQL to create and modify user permissions:
    MySQL :: MySQL 5.1 Reference Manual :: 12.7.1.1 CREATE USER Syntax

Similar Threads

  1. Connecting to local access database
    By Moses76 in forum JDBC & Databases
    Replies: 1
    Last Post: February 29th, 2012, 02:39 PM
  2. [SOLVED] Access Denied when extracting zip file.
    By techwiz24 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 18th, 2011, 07:50 PM
  3. access denied (java.io.FilePermission "report.jrxml" read)
    By banny7 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 3rd, 2011, 06:02 AM
  4. JFileChooser save dialog box "access is denied" error
    By byrdman in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 2nd, 2011, 01:45 PM
  5. Replies: 6
    Last Post: August 18th, 2010, 05:41 PM