MySQL MyIsam 存储引擎在创建索引的时候,索引键长度是有一个较为严格的长度限制的,所有索引键最大长度总和不能超过1000,而且不是实际数据长度的总和,而是索引键字段定义长度的总和。下面做个简单的测试,记录一下。
root@sky:~# mysql -u sky -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.0.51a-log MySQL Community Server (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
sky@127.0.0.1 : (none) 05:23:08> use test;
Database changed
sky@127.0.0.1 : test 05:23:11>
sky@127.0.0.1 : test 05:23:12>
先创建一个MyIsam表,字符集选择latin1,三个字段均设置为varchar 255,:
sky@127.0.0.1 : test 05:23:12> create table test_ind
-> (a varchar(255),
-> b varchar(255),
-> c varchar(255)
-> ) engine=myisam charset=latin1;
Query OK, 0 rows affected (0.01 sec)
创建效果:
sky@127.0.0.1 : test 05:23:32> show create table test_ind\G
***** ......
例子:将cdb_pms表subject字段中的Welcom to替换成 欢迎光临
UPDATE `cdb_pms`
SET `subject` = REPLACE(`subject`, ‘Welcome to’, ‘欢迎光临’)
WHERE INSTR(`subject`,’Welcome to’) < 0 替换cdb_posts表的message字段,将“viewthread.php?tid=3989”替换成“viewthread.php?tid=16546” UPDATE `cdb_posts`
SET `message`= REPLACE(`message`, ‘viewthread.php?tid=3989′, ‘viewthread.php?tid=16546′)
WHERE INSTR(`message`,’viewthread.php?tid=3989′) < 0 ; 删除所有的空格
UPDATE `es_product` SET `pro_pub_time` = TRIM(`pro_pub_time`) 删除所有饱含’['或者']‘或者’.'的字符
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, ‘[','') WHERE INSTR(`pro_pub_time`,'[') < 0
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, ']‘,”) WHERE INSTR(`pro_pub_time`,’]') < 0
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, ‘.’,'-’) WHERE INSTR(`pro_pub_time`,’.') < 0 替换所有含中文’-'的为英文’-’
UPDATE `es_prod ......
表名为table的表内容如下
Year month value
2009 1 1.1
2009 2 1.2
2009 3 1.3
2009 4 1.4
2010 1 2.1
2010 2 2.2
2010 3 2.3
2010 4 2.4
要求查询结果为
year m1 m2 m3 m4
2009 1.1 1.2 1.3 1.4
2010 2.1 2.2 2.3 2.4
mysql> select year,sum(case when month=1 then value end) as 'm1',sum(case when m
onth=2 then value end) as 'm2',sum(case when month=3 then value end)as 'm3' from
table2 group by year; ......
近来需要用Python对MySQL数据库进行操作。Python久闻其名,未见其“人”;数据库曾经很高分,早已还给先生,更无MySQL经验。于是一切从零开始,借机好好学习一番。
Python这个脚本语言确实名副其实,用了几天便喜欢上它啦。很简洁,很方便。以缩减作为模块分割符,读起来赏心悦目。python的内建数据类型(list, tuple, dict)以及内存管理机制使得变量的使用非常简单,写起代码来酣畅淋漓(当然还是应该动手前自个进行规划的好)。
关键的,Python已经流行了很久啦,各种模块很多很强大。比如其MySQL接口。利用Python,很容易的就将一些复杂的SQL过程重新实现了。实在不错。
数据库这边主要复习了下关系数据的相关概念,了解一些MySQL的具体语法和命令。因为主要是操作,暂时不涉及数据库的设计,就不多说了。感慨一下,数据库真是互联网公司的核心之一。
几个不错的参考文档:
Python:
《Python核心编程》
http://docs.python.org/tutorial/index.html
MySQL:
《数据库系统概念》
http://dev.mysql.com/doc/refman/5.1/zh/index.html
Python and MySQL:
http://www.kitebird.com/articles/pydbapi.html
http://mysql-python.sourceforge.net ......
RedHat Linux (Fedora Core/Cent OS)
1.启动:/etc/init.d/mysqld start
2.停止:/etc/init.d/mysqld stop
3.重启:/etc/init.d/mysqld restart
Debian / Ubuntu Linux
1.启动:/etc/init.d/mysql start
2.停止:/etc/init.d/mysql stop
3.重启:/etc/init.d/mysql restart
Windows
1.点击“开始”->“运行”(快捷键Win+R)
2.启动:输入 net stop mysql
3.停止:输入 net start mysql
提示
Redhat Linux 也支持service command,
启动:# service mysqld start
停止:# service mysqld stop
重启:# service mysqld restart
Windows下不能直接重启(restart),只能先停止,再启动。 ......
MySQL的mysqldump工具导入导出数据库!
1.导出整个数据库(Dos下)
mysqldump -u 用户名 -p 数据库名 > 导出的文件名
mysqldump -u chai -p smgp_apps_wcnc > chai.sql
2.导出一个表
mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名
mysqldump -u chai -p smgp_apps_wcnc users>chai.sql
3.导出一个数据库结构
mysqldump -u chai -p -d --add-drop-table smgp_apps_wcnc >d:\chai.sql
-d 没有数据 --add-drop-table 在每个create语句之前增加一个drop table
4.导入数据库
常用source 命令
进入mysql数据库控制台,
如mysql -u root -p
mysql>use 数据库
然后使用source命令,后面参数为脚本文件(如这里用到的.sql)
mysql>source d:\chai.sql ......