MySQL usage practices

Source: Internet
Author: User

1, the virtual machine installs the MySQL server, the host computer uses the Navicat tool and the Java code to access MySQL respectively, the Network diagram is as follows:

2. Check the server status of MySQL as follows:

3. View the database and data table contents on the server as follows:

4. On the host, use Navicat to view the contents as follows:

Look at the contents of the User data table, as in fact, there are many columns, the following is just one, from the results, it can be seen that there are 6 rows of records, this result and the server saw the content of the record is the same.

5. On the host, use Java code to view the contents of the database, the Java code is as follows:

1 /*2 * To-change the license header, choose License Headers in Project Properties.3 * To change this template file, choose Tools | Templates4 * and open the template in the editor.5  */6 7  PackageSequensesearch;8 ImportJava.sql.*;9 Ten /** One  * A  * @authorZhou -  */ -  Public classSequensesearch { the  -     /** -      * @paramargs the command line arguments -      */ +      Public Static voidMain (string[] args) { -Connection con=NULL; + Statement SQL; A ResultSet rs; at          -         Try{Class.forName ("Com.mysql.jdbc.Driver"); -         }         -         Catch(Exception e) {} -          -String uri = "Jdbc:mysql://192.168.248.156:3306/mysql?usessl=false"; inString user = "root"; -String password = "123456"; to         Try { +             //establish a connection to the database -Con =drivermanager.getconnection (URI, user, password); the         } *         Catch(SQLException e) {} $         Panax Notoginseng         Try{ -             //create an SQL statement object thesql =con.createstatement (); +rs = sql.executequery ("Select User, host from user"); A             //Execute Query the             //rs = sql.executequery ("SELECT * from student");  +              while(Rs.next ()) -             { $String users = rs.getstring (1); $String host = rs.getstring (2); -                  -System.out.printf ("%s\t", users); theSystem.out.printf ("%s\t", host); -System.out.printf ("\ n");Wuyi             } the              - con.close (); Wu         }             -         Catch(SQLException e) { About System.out.println (e); $         }    -     } -}
Java code access to MySQL

The results of the operation are as follows:

As you can see, the result is the same as the content on the server.

6. To summarize, the use of code access to the MySQL server, you need to load the corresponding API driver, that is, jdbc-mysql, if it is a Python code access, you need to load python-mysql.

MySQL usage practices

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.