2009-12-08 18:53
sql脚本是包含一到多个sql命令的sql语句,我们可以将这些sql脚本放在一个文本文件中(我们称之为“sql脚本文件”),然后通过相关的命令执行这个sql脚本文件。基本步骤如下:
1、创建包含sql命令的sql脚本文件
文件中包含一些列的sql语句,每条语句最后以;结尾,文件内容示例如下:
--创建表,使用“--”进行注释
create table 表名称
(
Guid Varchar(38) not null primary key,
Title Varchar(255),
) TYPE=InnoDB;
--在表A中增加字段Status
alter table A add Status TinyInt default '0';
--在表A上创建索引
create index XX_TaskId_1 on A(Id_);
--在A表中添加一条记录
Insert into A (Id,ParentId, Name) values(1,0,'名称');
--添加、修改、删除数据后,有可能需要提交事务
Commit;
2、执行sql脚本文件
方法一 使用dos命令执行(windows ......
2009-12-08 18:53
sql脚本是包含一到多个sql命令的sql语句,我们可以将这些sql脚本放在一个文本文件中(我们称之为“sql脚本文件”),然后通过相关的命令执行这个sql脚本文件。基本步骤如下:
1、创建包含sql命令的sql脚本文件
文件中包含一些列的sql语句,每条语句最后以;结尾,文件内容示例如下:
--创建表,使用“--”进行注释
create table 表名称
(
Guid Varchar(38) not null primary key,
Title Varchar(255),
) TYPE=InnoDB;
--在表A中增加字段Status
alter table A add Status TinyInt default '0';
--在表A上创建索引
create index XX_TaskId_1 on A(Id_);
--在A表中添加一条记录
Insert into A (Id,ParentId, Name) values(1,0,'名称');
--添加、修改、删除数据后,有可能需要提交事务
Commit;
2、执行sql脚本文件
方法一 使用dos命令执行(windows ......
PHP中的MYSQL常用函数总结
1、mysql_connect()-建立数据库连接
格式:
resource mysql_connect([string hostname [:port] [:/path/to/socket] [, string username] [, string password]])
例:
$conn = @mysql_connect("localhost", "username", "password") or dir("不能连接到Mysql Server");
说明:使用该连接必须显示的关闭连接
2、mysql_pconnect()-建立数据库连接
格式:
resource mysql_pconnect([string hostname [:port] [:/path/to/socket] [, string username] [, string password]])
例:
$conn = @mysql_pconnect("localhost", "username", "password") or dir("不能连接到Mysql Server");
说明:使用该连接函数不需要显示的关闭连接,它相当于使用了连接池
3、mysql_close()-关闭数据库连接
例:
$conn = @mysql_connect("localhost", "username", "password") or die("不能连接到Mysql Server");
@mysql_select_db("MyDatabase") or die("不能选择这个数据库,或数据库不存在");
& ......
PHP中的MYSQL常用函数总结
1、mysql_connect()-建立数据库连接
格式:
resource mysql_connect([string hostname [:port] [:/path/to/socket] [, string username] [, string password]])
例:
$conn = @mysql_connect("localhost", "username", "password") or dir("不能连接到Mysql Server");
说明:使用该连接必须显示的关闭连接
2、mysql_pconnect()-建立数据库连接
格式:
resource mysql_pconnect([string hostname [:port] [:/path/to/socket] [, string username] [, string password]])
例:
$conn = @mysql_pconnect("localhost", "username", "password") or dir("不能连接到Mysql Server");
说明:使用该连接函数不需要显示的关闭连接,它相当于使用了连接池
3、mysql_close()-关闭数据库连接
例:
$conn = @mysql_connect("localhost", "username", "password") or die("不能连接到Mysql Server");
@mysql_select_db("MyDatabase") or die("不能选择这个数据库,或数据库不存在");
& ......
经常在一个表中有父子关系的两个字段,比如empno与manager,这种结构中需要用到树的遍历。在Oracle 中可以使用connect by简单解决问题,参见http://blog.csdn.net/ylqmf/archive/2010/01/11/5172866.aspx,但MySQL 5.1中还不支持(据说已纳入to do中),要自己写过程或函数来实现。
一、建立测试表和数据:
view plaincopy to clipboardprint?
DROP TABLE IF EXISTS `channel`;
CREATE TABLE `channel` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cname` varchar(200) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;
/*Data for the table `channel` */
insert into `channel`(`id`,`cname`,`parent_id`)
values (13,'首页',-1),
(14,'TV580',-1),
(15,'生活580',-1 ......
Galera 是一套在 MySQL InnoDB 上面实现 Multi-master 且 synchronous replication 的系統。
该版本修复了9个bug,主要是处理 DDL 和 DML 的并发问题,另外基准MySQL版本升级到 5.1.41 。
下载地址: http://www.codership.com/en/downloads/galera
......
1, MySQL profiling
mysql> set profiling = 1;
mysql> select count(*) from test;
mysql> show profiles;
mysql> show profile for query 1;
2,mysql 监控
http://bbs.linuxtone.org/thread-1854-1-1.html
http://code.google.com/p/mysql-cacti-templates/ -> High performance for mysql 作者写的Cacti模板 ......
Mysql Explain 详解
一.语法
explain < table_name >
例如: explain select * from t3 where id=3952602;
二.explain输出解释
+----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+
1.id
我的理解是SQL执行的顺利的标识,SQL从大到小的执行.
例如:
mysql> explain select * from (select * from ( select * from t3 where id=3952602) a) b;
+----+-------------+------------+--------+-------------------+---------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+--------+-------- ......