#登录主用户,设置密码
mysql -uroot -p
#创建数据库
create database webmagic;
#新增用户
grant all privileges on webmagic.* to auss@localhost identified by "auss";
flush privileges;
#测试新用户
mysql -uauss -h 127.0.0.1 -p
3. 在Java里面测试
import java.sql.*;
import java.util.Properties;
publicclassDBDemo
{// The JDBC Connector Class.privatestaticfinal String dbClassName = "com.mysql.jdbc.Driver";
// Connection string. emotherearth is the database the program// is connecting to. You can include user and password after this// by adding (say) ?user=paulr&password=paulr. Not recommended!privatestaticfinal String CONNECTION =
"jdbc:mysql://127.0.0.1/webmagic";
publicstaticvoidmain(String[] args) throws
ClassNotFoundException,SQLException
{
System.out.println(dbClassName);
// Class.forName(xxx) loads the jdbc classes and// creates a drivermanager class factory
Class.forName(dbClassName);
// Properties for user and password. Here the user and password are both 'paulr'
Properties p = new Properties();
p.put("user","auss");
p.put("password","auss");
// Now try to connect
Connection c = DriverManager.getConnection(CONNECTION,p);
System.out.println("It works !");
c.close();
}
}