In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
To learn linux, you inevitably need to install the database, but you can't just install the data. If you want to operate the data, you also need a database driver. Many children's shoes who are new to linux will encounter problems in database installation and driver installation (me too). Then, here is the whole process of installing mysql on my Centos6.5 from never installing successfully to successfully executing the sql query. I hope that children's shoes with the same problems can get some help from them.
.
I won't go into details about the installation of mysql database here, but you can read it in another article of mine.
Http://blog.csdn.net/qixin1889/article/details/51298534
Here only talk about how to use the mysql driver to implement a simple query example after the successful installation of the mysql database, and share my experience.
1) after the mysql database is successfully installed, execute the following command with the root user (the installation of mysql must also be root)
# mysqladmin-uroot password 'root'
Change the password of the default Super Admin root during mysql database installation (note: this is the user of mysql, not the root of your linux system) to "root" or something else.
2), log in to the database
# mysql-u root-p
3) create a new database mydb
Create database mydb
4) create table test in mydb
Use mydb; create table test (id varchar (20), name varchar (20)); insert into test vlaues ('01th); insert into test vlaues (' 02th)
The above is to create the table test, the fields are id and name, and insert two pieces of data.
5) enter the home directory to write the test class
# vi Test.javaimport java.sql.*;public class Test {public static void main (String [] args) {try {Class.forName ("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306/mydb?us er=root&password=root"); Statement st = con.createStatement (); ResultSet rs = st.executeQuery ("select * from test") While (rs.next ()) {System.out.println ("id=" + rs.getString (1) + ", name=" + rs.getString (2));} catch (Exception e) {e.printStackTrace ();}
Save and exit.
6), compile and run
# javac Test.java
If you report it correctly, you can run it.
# java Test
The following error message will be prompted
Obviously, the driver for mysql cannot be found, so the next step is to solve the driver problem.
First of all, download the mysql driver, there are many on the Internet, I will not list the address. I use this version of mysql-connector-java-5.1.38-bin.jar.
Then, create a new folder mysql-con under / opt (name whatever, as long as there is no conflict), and put the downloaded driver in mysql-con.
Finally, and crucially, go to the / etc directory and add the path to the mysql driver in the CLASSPATH of the profile file, mine as follows
Then use the source profile command to make the modified file effective, which saves the trouble of logging back in. Then if you execute java Test again, it will show
Id=01,name=test01id=01,name=test02
This means that the driver has been loaded successfully.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.