好久没有整理东西,感觉自己越来越懒,正好近期有个MYSQL的项目(一个ORACLE的应用迁移到MYSQL),以前没有接触过MYSQL,但是也知道MYSQL数据库目前广泛的应用在各种个人、商务系统中,各种技术都比较成熟。把自己学习的一些过程总结一下,该文章设计到的内容都没有做太详细的阐述,只是一个简单的入门手册。
MYSQL支持数个存储引擎作为对不同表的类型的处理器。
mysql> SHOW ENGINES;
+------------+---------+--------------------------------------------------------
--------+
| Engine | Support | Comment
|
+------------+---------+--------------------------------------------------------
--------+
| MyISAM | YES | Default engine as of MySQL 3.23 with great performance
|
| MEMORY | YES | Hash based, stored in memory, useful for temporary tabl
es |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign k
eys |
| BerkeleyDB | NO | Supports transactions and page-level locking
|
| BLACKHOLE | NO | /dev/null storage engine (anything you write t ......
Oracle函数和mysql函数比较
1. Oracle中的to_number()转换成数字;
Oracle> Select to_number(‘123’) from dual; ----- 123;
select to_char(33) from dual;---- 33;
Mysql> Select conv(‘123’,10,10); ---- 123;
Select cast(‘123’ as signed integer);--- 123
Select cast(‘-123’ as signed integer);--- -123
select cast(33 as char(2) ); -------   ......
Oracle函数和mysql函数比较
1. Oracle中的to_number()转换成数字;
Oracle> Select to_number(‘123’) from dual; ----- 123;
select to_char(33) from dual;---- 33;
Mysql> Select conv(‘123’,10,10); ---- 123;
Select cast(‘123’ as signed integer);--- 123
Select cast(‘-123’ as signed integer);--- -123
select cast(33 as char(2) ); -------   ......
在表中已有大量的index的情况下插入大量数据,可以采用先将索引删除,然后再插入数据,然后再重新建立索引。之所以这样会快是因为???
7.2.14 Speed of INSERT Statements
The time to insert a record is determined by the following factors, where the numbers indicate approximate proportions:
* Connecting: (3)
* Sending query to server: (2)
* Parsing query: (2)
* Inserting record: (1 x size of record)
* Inserting indexes: (1 x number of indexes)
* Closing: (1)
This does not take into consideration the initial overhead to open tables, which is done once for each concurrently running query.
The size of the table slows down the insertion of indexes by log N, assuming B-tree indexes.
You can use the following methods to speed up inserts:
* If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALU ......
update :单表的更新不用说了,两者一样,主要说说多表的更新
Oracle> Oracle的多表更新要求比较严格,所以有的时候不是很好写,我们可以试试Oracle的游标
(游标参考:http://blog.csdn.net/lovelyhermione/archive/2009/08/18/4457500.aspx)
update (
select t.charger_id_ new_charger_id_
from t_cus_year_status t
left join t_customer_infos cus on cus.id_ = t.cus_id_
&n ......
update :单表的更新不用说了,两者一样,主要说说多表的更新
Oracle> Oracle的多表更新要求比较严格,所以有的时候不是很好写,我们可以试试Oracle的游标
(游标参考:http://blog.csdn.net/lovelyhermione/archive/2009/08/18/4457500.aspx)
update (
select t.charger_id_ new_charger_id_
from t_cus_year_status t
left join t_customer_infos cus on cus.id_ = t.cus_id_
&n ......
MySQL的备份方式,目前我想到的有五种,有可能还有
1,mysqldump方式,加上具体参数名(单库,多库,触发器,存储过程,表结构,字符集,–single-transaction,等等)
2,mysqlhotcopy 只能备份myisam数据表备份,速度相当快,因为是文件拷贝,可能瞬间被锁表,任何的数据操作,比如插入和更新都会挂起。
3,LVM的快照功能进行数据库分区的备份,这种方法是利用的逻辑卷的镜像功能,对整个分区进行在线备份,这种备份数据量大,而且备份性能低下,因为每次备份都是整个镜像,不能针对数据做备份。桶装备份
4,开启二进制同步日志功能,主从复制,从机器做备份功能。
5,在线的热备份,采用开源的 Xtrabackup 备份工具对innodb 数据表进行在线备份,测试阶段。
下面是备份的xtrabackup的测试例子。
[@root.localhost.nova ~]# /usr/bin/innobackupex-1.5.1 –user=root
–defaults-file=/home/mysql/my.cnf –socket=/home/mysql/mysql.sock
–database=serverinfo –slave-info –stream=tar /root/ |gzip >
/root/bak_mysql.tar.gz
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy.
All R ......
1、MySQL常用命令
create database name; 创建数据库
use databasename; 选择数据库
drop database name 直接删除数据库,不提醒
show tables; 显示表
describe tablename; 表的详细描述
select 中加上distinct去除重复字段
mysqladmin drop databasename 删除数据库前,有提示。
显示当前mysql版本和当前日期
select version(),current_date;
2、修改mysql中root的密码:
shell>mysql -u root -p
mysql> update user set password=password(”xueok654123″) where user=’root’;
mysql> flush privileges //刷新数据库
mysql>use dbname; 打开数据库:
mysql>show databases; 显示所有数据库
mysql>show tables; 显示数据库mysql中所有的表:先use mysql;然后
mysql>describe user; 显示表mysql数据库中user表的列信息);
3、grant
创建一个可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令something做这个
mysql> grant all privileges on *.* to user@localhost identified by ’something’ with
增加新用户
格式:grant select on 数据库. ......