易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : mysql

MySQL Basic Knowledge

MySQL版本: Server version: 5.1.44 Source distribution
修改root密码
如果没有密码使用下面的命令, 将密码设为"123456"
$ mysqladmin -u root password 123456
如果有密码使用下面的命令, 将密码改为"123456"
$ mysqladmin -u root -p password 123456
Enter password:
用户账户管理
添加账户:
http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#user-account-management
提到的方法不适用:
mysql>
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'

IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
根据http://dev.mysql.com/doc/refman/5.1/en/adding-users.html所说, 要先create user, 然后再使用grant, 根据尝试, 在mysql中, 语句不区分大小写. 正确的方法如下:
mysql> create user 'frank'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'frank'@'localhost' INDENTIFIED BY '123456' WITH GRANT OPTION;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL ......

MYSQL外键(Foreign Key)的使用(二)

作者:Dirk (dirk.ye AT gmail.com)
Url:http://dirk.pdx.cn
日期:2004/12/08
首先,目前在产品环境可用的MySQL版本(指4.0.x和4.1.x)中,只有InnoDB引擎才允许使用外键,所以,我们的数据表必须使用
InnoDB引擎。
下面,我们先创建以下测试用数据库
表:
CREATE TABLE `roottb` (
`id` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
`data` VARCHAR(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) TYPE=InnoDB;
CREATE TABLE `subtb` (
`id` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
`rootid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`data` VARCHAR(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
INDEX (`rootid`),
FOREIGN KEY (`rootid`) REFERENCES roottb(`id`) ON DELETE CASCADE
) TYPE=InnoDB;

注意:
1、必须使用InnoDB引擎;
2、外键必须建立索引(INDEX);
3、外键绑定关系这里使用了“ ON DELETE
CASCADE”,意思是如果外键对应数据被删除,将关联数据完全删除,更多信息请参考MySQL手册中关于InnoDB的文档;
好,接着我们再来插入测试数据:
INSERT INTO `roottb` (`id`,`data`)
VAL ......

Mysql查询分页

说明:这是一个实例,其中有些东西是可以抽取出来的,作为一个公共的方法,可是实现复用
public class TestService {
public static TestService test=null;
public static TestService getTestService(){
if(test==null){
test=new TestService();
}
return test;
}
public List getTest(int pageNow ,int pageSize){
String sql="select count(*) from user";
Connection conn=DB.getConn();
Statement stmt=DB.getStmt(conn);
ResultSet rs=DB.getRs(stmt, sql);
int num;
try {
rs.next();
num=rs.getInt(1);

} catch (SQLException e) {
e.printStackTrace();
}
sql="select *from user limit "+(pageNow*pageSize-pageSize)+","+pageSize;
PreparedStatement pstmt=DB.getPstmt(conn, sql);
List list=new ArrayList<Test>();
try {
rs=pstmt.executeQuery(sql);
 
while(rs.next()){
Test t=new Test();
t.setId(rs.getInt("id"));
t.setAge(rs.getInt("age"));
t.setName(rs.getString("name"));
list.add(t);
}
} catch (SQLE ......

mysql replication


<!--
/* Font Definitions */
@font-face
{font-family:Courier;
panose-1:2 7 4 9 2 2 5 2 4 4;
mso-font-alt:"Courier New";
mso-font-charset:0;
mso-generic-font-family:modern;
mso-font-format:other;
mso-font-pitch:fixed;
mso-font-signature:3 0 0 0 1 0;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:Arial;
mso-fareast-font-family:宋体;
mso-fareast-language:EN-US;}
h3
{m ......

mysql 导入导出数据方法

1:>;create databases newname(在新的server上建立空的数据库)
2:#/usr/local/mysql/bin/mysqldump databasename >;*.sql(在旧的服务器上导出数据库)
3:#/usr/local/mysql/bin/mysql databasename < *.sql(在新的服务器上导入*.sql) ......

MyEclipse6.6 连接MySQL的数据库配置

1、打开MyEclipse6.6
2、选择菜单:Window/Open Perspective/MyEclipse Database Explorer,点击OK,在左边打开DB Brower窗口。
3、在DB Brower窗口内任意空白处击右键,选择New命令,弹出Database Driver窗口
4、本窗口各项说明:
   Driver template: MySQL Connector/J   选择驱动模板
   Driver name: mybook      任何起个名字
   Connection URL:jdbc:mysql://127.0.0.1:3306/book  (book要改成你要连数据库的名字)
    User name:root  (你数据库的用户名)
    Password:root  (你数据库的口令)
    Driver JARs:点击Add JARs选择你的驱动包所在路径 (包括包名)
   Driver classname:com.mysql.jdbc.Driver
   
5、点击Finish,建立完成。
6、进行连接,在DB Brower窗口选中你刚建的mybook,点击DB Brower窗口标题栏右侧的三角形图标,光标移动到其上时,会显示“Open Connection”提示。
7、根据提示输入密码:root  (选中save password后下次就不用输入密码了),点击OK
8 ......
总记录数:2220; 总页数:370; 每页6 条; 首页 上一页 [75] [76] [77] [78] 79 [80] [81] [82] [83] [84]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号