Presentation is loading. Please wait.

Presentation is loading. Please wait.

MySQL root 암호 $ mysqladmin -u root -p password new-password $ mysql -u root mysql mysql> update user set password = password('new-password') where user.

Similar presentations


Presentation on theme: "MySQL root 암호 $ mysqladmin -u root -p password new-password $ mysql -u root mysql mysql> update user set password = password('new-password') where user."— Presentation transcript:

1

2 MySQL root 암호 $ mysqladmin -u root -p password new-password $ mysql -u root mysql mysql> update user set password = password('new-password') where user = 'root'; mysql> flush privileges; mysql> set password for root = password('new-password'); $ mysql -u root -p

3 MySQL DB 생성 myslq> show databases; mysql> create database DB 명 ;

4 MySQL 사용자 추가 mysql> use mysql mysql> INSERT INTO user VALUES('%', ' 사용자 ', PASSWORD(' 비밀번호 '), -> 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y'); mysql> INSERT INTO db (Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv) -> VALUES('%', 'DB 명 ', ' 사용자 ', 'Y', 'Y', 'Y', 'Y','Y','Y'); mysql> grant all privileges on dbuser.* to dbuser@localhost identified by 'password' with grant option; mysql> grant all privileges on `dbuser_%`.* to dbuser@localhost identified by 'password' with grant option; mysql> GRANT ALL on DB 명.* TO id@'localhost' ; mysql> GRANT ALL on DB 명.* TO id; mysql> GRANT ALL on DB 명.* TO id@'xxx.xxx.xxx.%'; % 는 부분적 모든 * 는 모든

5 import java.sql.*; public class Connect { public static void main (String[] args) { Connection conn = null; try { String userName = "testuser"; String password = "testpass"; String url = "jdbc:mysql://localhost/test"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); } catch (Exception e) { System.err.println ("Cannot connect to database server"); } finally { if (conn != null) { try { conn.close (); System.out.println ("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } forName: 해당 클래스가 존재하면 그 클래스를 리턴함 newInstance: 클래스의 인스턴스를 생성함 public static Connection getConnection(String url, String user, String password) throws SQLExceptionConnectionString SQLException

6 Statement s = conn.createStatement (); int count; s.executeUpdate ("DROP TABLE IF EXISTS animal"); s.executeUpdate ( "CREATE TABLE animal (" + "id INT UNSIGNED NOT NULL AUTO_INCREMENT," + "PRIMARY KEY (id)," + "name CHAR(40), category CHAR(40))"); count = s.executeUpdate ( "INSERT INTO animal (name, category)" + " VALUES" + "('snake', 'reptile')," + "('frog', 'amphibian')," + "('tuna', 'fish')," + "('racoon', 'mammal')"); s.close (); System.out.println (count + " rows were inserted"); StatementStatement createStatement() throws SQLExceptionSQLException int executeUpdate(String sql) throws SQLExceptionStringSQLException Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

7 Statement s = conn.createStatement (); s.executeQuery ("SELECT id, name, category FROM animal"); ResultSet rs = s.getResultSet (); int count = 0; while (rs.next ()) { int idVal = rs.getInt ("id"); String nameVal = rs.getString ("name"); String catVal = rs.getString ("category"); System.out.println ( "id = " + idVal + ", name = " + nameVal + ", category = " + catVal); ++count; } rs.close (); s.close (); System.out.println (count + " rows were retrieved"); ResultSetResultSet executeQuery(String sql) throws SQLExceptionStringSQLException Executes the given SQL statement, which returns a single ResultSet object. ResultSetResultSet getResultSet() throws SQLExceptionSQLException Retrieves the current result as a ResultSet object. This method should be called only once per result. boolean next() throws SQLExceptionSQLException Moves the cursor froward one row from its current position. A ResultSet cursor is initially positioned before the first row; int getInt(String columnLabel) throws SQLExceptionStringSQLException Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language. StringString getString(String columnLabel) throws SQLExceptionStringSQLException Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language. PreparedStatement s; s = conn.prepareStatement ( "INSERT INTO animal (name, category) VALUES(?,?)"); s.setString (1, nameVal); s.setString (2, catVal); int count = s.executeUpdate (); s.close (); System.out.println (count + " rows were inserted");

8 import java.sql.*; public class Hello { public static void main(String[] args) { try { // The newInstance() call is a work around for some // broken Java implementations Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception ex) { // handle the error } Connection conn = null; try{ conn = DriverManager.getConnection("jdbc:mysql://localhost", "bjkim","qudwlsl1"); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } Statement stmt = null; ResultSet rs = null; try{ stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM test.user"); // or alternatively, if you don't know ahead of time that // the query will be a SELECT... if (stmt.execute("SELECT * FROM test.user")) { rs = stmt.getResultSet(); } } catch(Exception ex) { // handle the error } try{ while (rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); int age = rs.getInt("age"); System.out.println(id + " " + name + " " +age); } }catch(Exception ex) { // handle the error } }

9 MyMessenger gui 작성


Download ppt "MySQL root 암호 $ mysqladmin -u root -p password new-password $ mysql -u root mysql mysql> update user set password = password('new-password') where user."

Similar presentations


Ads by Google