存档

文章标签 ‘MySQL’

[MySQL] 相关SQL语句

2010年1月14日 stone 没有评论

连接数据库:mysql [host] –u [user] –p
查看数据库:show databases;  列出数据库服务器上所有数据库
查看当前使用的数据库:select database(); 
使用数据库:use [database name]  ; 切换到需要操作的数据库
查看表:      show tables;  列出当前所在数据库的所有表
查看表结构:describe [table name] ;  查看表结构

数据库的授权:grant all privileges on *.* to 'root'@'localhost' identified by 'zg'
这句话的意思是让用户root可以从localhost登陆,并对所有的数据库有权限,密码是zg
它相当于在数据库mysql的user表中添加了一条记录,此表以user与host为主键
如想更新密码可以这样:update user set password=password(密码) where user=? and password=?

导入.sql文件(该文件包含表及相关数据):
[root@mylocal001 ~]# mysql -u root -p posdb < /soft/war/posdb.sql

LIMIT子句
MS SQLSERVER 中有SELECT TOP语句, Oracle中有ROWNUM序列,那么MYSQL中如何实现select top n效果?
使用Mysql中的LIMIT子句
用法: select * from Table limit n,m;
limit n,m的含义是从n开始取,取m条记录

*当使用update语句时,LIMIT子句用于给定一个限值,限制可以被更新的行的数目。
update Table set col_name1=expr1 [, col_name2=expr2 ...] limit 1000;

查看系统中支持的存储引擎类型:show engines;
查看某个存储引擎的具体信息: show engine InnoDB status;
创建表时指定存储引擎的类型: CREATE TABLE tablename (id int, title char(20)) ENGINE = INNODB;
修改现有的表使用的存储引擎:  ALTER TABLE tablename ENGINE = MyISAM;
查看某个库中所有表的存储引擎:show table status from DBName;
查看某个库中单个表的存储引擎:show create table DBName.TableName;

查看Mysql版本(三种方法):
mysql>status;
mysql>select version();
[root@mylocal001 ~] # mysql -V

分类: Note 标签:

[MySQL] Apply secrurity Settings 失败 问题记录

2009年5月4日 stone 没有评论

机器环境: Redhat RHEL 5 中vmware下的XP虚拟系统 .

安装Mysql5.1.33在MySQL Server Instance Config Wizard时,Apply secrurity Settings 失败,错误信息为不能连接到该端口,请查看是否关闭防火墙,能及相关端口是否可用之类的提示;查看Linux系统的防火墙规则,没有任何限制,而XP自身的防火墙也关闭了,相关端口也没被占用,试了几次(完全卸载重新安装)都不能通过Apply secrurity Settings 这一步。

最后无意中在set network options 中将Add firewall exception for this port 选项选中,再次Execute,配置成功!

分类: Note 标签:

[MySQL] MySQL区分大小写问题

2009年4月22日 stone 没有评论

这次一个数据采集的项目在开发的时候在WINDOWS平台下开发的,开发完了之后在LINUX环境上部署好之后,运行时MySQL数据库报错,提示为某个表不存在之类的错误信息,后来修改了MySQL的配置文件将大小写敏感去掉,问题解决。

这个问题的根源在于,在 MySQL 中,数据库和表其实就是数据目录下的目录和文件,因而,操作系统的敏感性决定数据库和表命名的大小写敏感。这就意味着数据库和表名在 Windows 中是大小写不敏感的,而在大多数类型的 Unix/Linux 系统中是大小写敏感的。

MySQL大小写敏感可以通过配置文件的lower_case_table_names参数来控制。

WINDOWS:
编辑MySQL安装目录下的my.ini 文件,在[mysqld]节下 添加 lower_case_table_names=0 (备注:为0时大小写敏感,为1时大小写不敏感,默认为1),可以实现MySql按照建表Sql语句的大小写状态来定义表名。

LINUX:
编辑/etc/my.cnf文件,在[mysqld]节下 添加 lower_case_table_names 参数,并设置相应的值 (备注:为0时大小写敏感,为1时大小写不敏感,默认为0)。

关于 数据目录

数据目录是用来存放数据表和相关信息的地方,是数据库的核心。在MySQL中的数据目录根据不同平台的有一些差异:

在Unix/Linux系统上,如果用源码编译安装,数据目录的位置默认是在/usr/local/mysql/var中;

在UNIX/Linux系统上,如果用二进制发行版安装,数据目录的位置默认是在/usr/local/mysql/data中;

在Windows系统上,数据目录的位置默认是在C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data中;

PS: Identifier Case Sensitivity

How table and database names are stored on disk and used in MySQL is affected by the lower_case_table_names system variable, which you can set when starting mysqld. lower_case_table_names can take the values shown in the following table. This variable does not affect case sensitivity of trigger identifiers. On Unix, the default value of lower_case_table_names is 0. On Windows the default value is 1. On Mac OS X, the default value is 2.

Value Meaning
0 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive. Note that if you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive filesystem and access MyISAM tablenames using different lettercases, index corruption may result.
1 Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
2 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on filesystems that are not case sensitive! InnoDB table names are stored in lowercase, as for lower_case_table_names=1.
分类: Note 标签:

[MySQL] Could not start the service MySQL 解决方法

2009年4月15日 stone 没有评论

安装mysql 5.1.33,在运行Server Instance Configuration wizard时的Execute configurattion步骤中的第三项Start Service进出错,错误提示为Could not start the service MySQL (出现这种情况一般是因为装过mysql,卸载不干净造成的。卸载后重启后再重装。注意看下服务,如果未能卸载,可以用mysqld-nt -remove卸载)。

具体方法如下:
查看服务中有没有mysql,如果有将该服务停掉;
在控制面板中运行添加删除程序,将mysql卸载;
卸载后打开注册表,查看HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services 下的键值,如果有相关mysql键值(mysql、mysqladmin)则删掉,即可;
重启,将mysql的安装残余目录删掉 (查看服务,此时服务中已没有mysql);
重新安装mysql.安装后先不要运行Server Instance Configuration wizard,重启后在开始菜单中运行该向导,即可。

PS:一种值得参考的方法
(
Remember, windows machines love being rebooted.
For less headaches, do the following:

Uninstall mysql. Reboot the computer. Reinstall mysql, but don't configure yet! Reboot the computer again. Then run Mysql Instance Config Wizard (found in START menu).

Good Luck! :)
)

分类: Note 标签: