使用SHOW语句找出服务器上当前存在什么数据库:
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bugmag |
| mysql |
| test |
+--------------------+
4 rows in set (0.01 sec)
访问bugmag库
mysql> use bugmag
Database changed
如果想访问其他库,直接使用use XXXX即可。如:
mysql> use test
Database changed
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 tables |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys |
| BerkeleyDB | NO | Supports transactions and page-level locking |
| BLACKHOLE | NO | /dev/null storage engine (anything you write to it disappears) |
| EXAMPLE | NO | Example storage engine |
| ARCHIVE | YES | Archive storage engine |
| CSV | NO | CSV storage engine |
| ndbcluster | NO | Clustered, fault-tolerant, memory-based tables |
| FEDERATED | NO | Federated MySQL storage engine |
| MRG_MYISAM | YES | Collection of identical MyISAM tables |
| ISAM | NO | Obsolete storage engine |
+------------+---------+----------------------------------------------------------------+
12 rows in set (0.00 sec)
字符串
字符串指用单引号(‘'’)或双引号(‘"’)引起来的字符序列。例如:
'a string example'
"a string example"
转义字符:
/0
ASCII 0(NUL)字符。
/'
单引号(‘'’)。
/"
双引号(‘"’)。
/b
退格符。
/n
换行符。
/r
回车符。
/t
tab字符。
/Z
ASCII 26(控制(Ctrl)-Z)。该字符可以编码为‘/Z’,以允许你解决在Windows中ASCII 26代表文件结尾这一问题。(如果你试图使用mysql db_name < file_name,ASCII 26会带来问题)。
//
反斜线(‘/’)字符。
/%
‘%’字符。参见表后面的注解。
/_
‘_’字符。参见表后面的注解。
‘/%’和‘/_’序列用于搜索可能会解释为通配符的模式匹配环境中的‘%’和‘_’文字实例。请注意如果你在其它环境中使用‘/%’或‘/_’,它们返回字符串‘/%’和‘/_’,而不是‘%’和‘_’
有几种方式可以在字符串中包括引号:
· 在字符串内用‘'’引用的‘'’可以写成‘''’。
· 在字符串内用‘"’引用的‘"’可以写成‘""’。
· 可以在引号前加转义字符(‘/’)。
· 在字符串内用‘"’引用的‘'’不需要特殊处理,不需要用双字符或转义。同样,在字符串内用‘'’引用的‘"’也不需要特殊处理。
下面的SELECT语句显示了引用和转义如何工作:
mysql> SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '/'hello';
+-------+---------+-----------+--------+--------+
| hello | "hello" | ""hello"" | hel'lo | 'hello |
+-------+---------+-----------+--------+--------+
如果你想要在字符串列内插入二进制数据(例如BLOB),必须通过转义序列表示下面的字符:
NUL
NUL字节(ASCII 0)。用‘/0’表示该字符(反斜线后面跟一个ASCII‘0’字符)。
/
反斜线(ASCII 92)。用‘//’表示该字符。
'
单引号(ASCII 39)。用‘/'’表示该字符。
"
双引号(ASCII 34)。用‘/"’表示该字符。
布尔值
常量TRUE等于1,常量FALSE等于0。常量名可以写成大写或小写。
mysql> SELECT TRUE,true,FALSE,false;
-> 1,1,0,0