锁定数据库:flush tables with read lock,解锁:unlock tables
切换字符集:charset gb2312,show character set查看支持的字符集
SQL语句
增删改查: select 列 from 表 where 条件 group by 分组 having 分组条件 order by 排序 limit 条数 insert into 表(列) values(值),insert into 表(列) select语句 delete from 表 where 条件 order by 排序 limit 条数 update 表 set 列=值 where 条件 order by 排序 limit 条数
表、视图、索引 create database 库 default character set utf8; create table 表(列定义)[表选项],alter table 表 add column 列定义 create view 视图 as 查询,drop view 视图 create index 索引 on table(列)
select host,user,password from user where user='root';需要新建管理员时记住原来的密码
update user set password=password('12345') where user='root';直接修改root密码
INSERT INTO `user` VALUES ('%', 'root', '*4ACFE3202A5FF5CF467898FC58AAB1D615029441', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'N', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0');添加管理员数据,密码可通过update语句重设,或直接传入password('12345') 使用grant语句也可以添加用户,比insert语句要简便些,之后用mysql客户端管理用户更方便。 grant all privileges on *.* to root@'%' identified by 'admin' with grant option;
grant all privileges on *.* to root@'%' identified by '12345';对所有数据库所有表拥有所有权限
flush privileges;权限修改立即生效(下面的with grant option或许会用到)
权限管理: grant select on db.book to user@'host';给普通用户查询数据库中book表的权限 grant all privileges on db.* to dbadmin@'host';给普通数据库管理员整个数据库的权限 grant all privileges on *.* to dba@'host';给高级数据库管理员所有权限 show grants;查看自己的权限show grants for user@'host';查看别人权限 最高管理员拥有所有权限,且能够给别人赋予权限with grant option,收回权限则revoke GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '3e5169875ba3ab98' WITH GRANT OPTION
修改字符集:
直接修改时不能影响已有数据 alter database character set ***和alter table tablename character set ***
查询时指定返回映射、参数类型:<![CDATA[ sql ]]>内可直接用与&,否则需转义 <select id="findById" resultMap="book" parameterClass="string"> select * from book where id=#id# and (state & 1) != 0 </select> 返回int查询数量,调用getSqlMapClientTemplate.queryForObject("namespace.id") <select id="countByAuthor" resultClass="int" parameterClass="com.model.Book"> select count(*) from book where author=#author# </select> 常用的分页查询 <select id="getPager" resultMap="book" parameterClass="java.util.HashMap"> select book.* from book as book limit $start$,$length$ </select>