mysql基础操作
1、系统管理
mysql -h主机地址 -u用户名 -p
连接MYSQL(在mysql/bin)
exit
退出MYSQL命令
mysqladmin -u用户名 -p旧密码 password新密码
修改密码(在mysql/bin)
grantselect[insert][,update][,delete]on数据库.*to用户名@localhost("%", 表示任何主机)identifiedby "密码"
增加用户
mysqldump –u root –p opt数据库名>备份文件名
备份数据库(在mysql/bin)
mysql –u root –p < batchfile (例如备份文件名)
使用批处理
mysql.server start
启动服务器
mysql.server stop
停止服务器
msql.serverlog
2、查询命令
select version()
查询版本号
select current_date
查询当前日期
3、显示命令
show databases
显示数据库列表
show tables 显示库中的数据表
describe 表名 显示数据表的结构
select * from 表名 显示表中的记录
select what_to_select from which table [whereconditions_to_satisfy and (or) where conditions_to_satisfy] 从一个表中检索数据『满足条件』
select 字段1,字段2,… from 表名 显示特定列的值
select * from 表名 order by 字段名 排序行
select 字段1,包含字段2的运算式as 新字段 from 表名 字段值运算操作
select 字段1 is null(is not null) 空值操作
Select*from表名where字段名like(not like) “ 字符”
注: 允许使用“_”匹配任何单个字符, 而“%” 匹配任意数目字符 模式匹配
Select * from表名where字段名regexp(not regexp)或者rlike(not rlike) “.”匹配任何单个的字符 一个字符类[…]匹配方框内任何字符。例如[a],[asd],[az] 匹配任何小写字母,[09] 匹配任何数
字。 “*”匹配零个或者多个在它前面的东西。 正则表达式区分大小写[aA] 。 如果它出现在被测试值的任何地方,模式都匹配。 定位,在模式开始处用“^”,结尾处用“$”,例如“^b”
扩展正则表达式
Select count(*) from 表名
Select 字段名,count(*) from 表名 group by 字段名 行计数
4、编辑命令
use database 库名
使用的数据库
create data
相关文档:
建立数据库:
我的数据库images
create table img (
id int primary key auto_increment,
name varchar(80),
pic longblob
)
要保证网站根目录 有个 images 文件夹
插入数据库 从本地文件夹
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*,java.io.*" ......
共3个文件
IncDB.php数据库连接
index.php首页
InsetToDB.php数据库操作
数据库lguestbook里面建表
CREATE TABLE `intd` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) character set utf8 collate utf8_bin N ......
添加字段:
MYSQL
alter table tb add col2 varchar(10)
MSSQL2000
alter table tb add col2 varchar(10)
修改字段:
MYSQL
alter table tb modify col2 varchar(20)
MSSQL2000
alter table tb alter column col2 varchar(20)
删除字段:
MYSQL
alter table tb drop column col ......
安装后MYSQL5后,发现启动出错.
出错代码:1067
解决办法如下:
删除%windows%/my.ini
删除其它地方的my.ini
在mysql安装目录下把my-small.ini复制为my.ini
在my.ini最后一行插入:
CODE:
[mysqld]
#设置basedir指向mysql的安装路径
basedir=C:\mysql-5.1.11-beta-win32
datadir=C:\mysql-5.1.11-beta-win32\dat ......
http://blog.csdn.net/iamstillzhang/archive/2007/04/01/1548377.aspx
用mysql源码进行SQL解析
Mysql是通过yacc进行SQL语句解析的,这里介绍一下如何使用mysql的源码进行SQL语句解析。由于Mysql的源代码注释比较少,而且缺少资料,所有些地方研究不够深入。
1 Filed介绍
MY ......