Log a bug that myeclipes remote connection to MySQL
today, when playing the framework hibernate, there is a very confusing bug, say not much, first look at the bug
for user ' root ' @ ' localhost ' (using Password:yes)
Then a variety of search Baidu, some are said to change the password, some are said to have permission problems, it is strange I, not to connect Linux under the window System MySQL (my MySQL database is installed under the virtual machine)
Based on the reflex, I checked my hibernate configuration file.
// 192.168.174.130:3306/hibernate_day01</property> <property name= "Hibernate.connection.username" >root</property> <property name= "Hibern Ate.connection.password ">root</property> <!--dialect of the database--<property name=" Hibernate.dialect >org.hibernate.dialect.MySQLDialect</property> <!--Optional configuration--<!--mapping profile, which needs to map the mapped profile--&G T <mapping resource= "Com/heima/domain/customer.hbm.xml"/> </session-factory></ Hibernate-configuration>
If there is no problem with the configuration, it could be a permissions issue
1. First assign the newly created database to local user permissions
Grant all privileges the hibernate_day01.* to [e-mail protected] identified by ' Root ';
2. Then open the network all rights to the account
Grant all privileges the hibernate_day01.* to ' root ' @ '% ' identified by ' root ';
Of course, all of them can specify a number of permissions, such as the restriction of incremental changes, such as the IP address because it is remote access, I set the Linux IP address
3. Make the above permissions effective
Flush privileges;
4. Test the connection
@Test Public voidTestsave () {/*** 1. load config file first * 2. Create a Sessionfactory object, Generate session objects (sessions) * 3. Turn on Transaction * 5. Write saved code * 6. Transactions * 7. Releasing Resources*/ //1. Load the configuration file firstConfiguration config=NewConfiguration (); //default load hibenate.cfg.xml configuration file in src directoryconfig.configure (); //Create a Sessionfactory objectSessionfactory factory=config.buildsessionfactory (); //Create Session ObjectSession session=factory.opensession (); //Open TransactionTransaction tr=session.begintransaction (); //write the saved codeCustomer c=NewCustomer (); //c.setcust_id (cust_id); The primary key is automatically incremented and does not need to be set by itselfC.setcust_name ("Test"); C.setcust_level ("2"); C.setcust_phone ("110"); //Save the data and manipulate the object to the table structure of the operating databaseSession.save (c); //Commit a transactionTr.commit (); //Freeing ResourcesSession.close (); Factory.close (); }
The junit appears green to indicate that the operation was successful
Look at the database, the data has been inserted into the table
Record a bug in MySQL under Windows system myeclipes connection Linux