易截截图软件、单文件、免安装、纯绿色、仅160KB

定制你的MySQL命令行

我在登录MySQL后的命令行是这个样子的:
warmbupt@pchuang:/windows/MyCode/SS$ mysql -u root -ppassw0rd
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.37-1ubuntu5.1 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
通过一系列改造,我们可以得到一个更加user-friendly的命令行提示符。
我们试着显示用户名、主机名和正在使用的数据库名称:
在shell命令行中设置环境变量:
export MYSQL_PS1="\u@\h [\d]> "
其中
\u – Username 用户名
\h – Hostname 主机名
\d – Current mysql database 当前数据库
当然,你可以将该命令写入bashrc以后在bash下使用都能得到这样的命令行提示符了。或者你可以在MySQL的配置文件/etc/my.cnf 或.my.cnf设置:
prompt=\\u@\\h [\\d]>\\_
另外,你在MySQL内也可以设置:
prompt \u@\h [\d]>
在你想回归原始的时候你可以在MySQL中键入prompt即可回归(回到在MySQL外部的设置,若你在bashrc中写入的话即回归到bashrc中的设置状态)。
附变量表:
Generic variables:
\S displays semicolon
\’ displays single quote
\” displays double quote
\v displays server version
\p displays port
\\ displays backslash
\n displays newline
\t displays tab
\ displays space (there is a space after \ )
\d displays default database
\h displays default host
\_ displays space (there is a underscore after \ )
\c displays a mysql statement counter. keeps increasing as you type commands.
\u displays username
\U displays username@hostname accountname
Date related variables:
\D displays full current date (as shown in the above example)
\w displays 3 letter day of the week (e.g. Mon)
\y displays the two digit year
\Y displays the four digit year
\o displays month in number
\O displays 3 letter month (e.g. Jan)
\R displays current time in 24 HR format
\r displays current time in 12 hour format
\m displays the minutes
\s displays the seconds
\P displays AM or PM


相关文档:

mysql远程备份

新建backup.bat
设置mysqldump全局环境变量或使用时写入绝对路径
@echo off
set date0=%date:~0,10%
set time0=%time:~0,8%
set time1=%time:~0,2%
set time2=%time:~3,2%
set time3=%time:~6,2%
echo %time0%
echo %time1%
echo %time2%
echo %time3%
mysqldump -u<用户> -p<密码> -h <ip ......

mysql过程游标

DELIMITER $$
DROP PROCEDURE IF EXISTS `heli`.`prodtest` $$
CREATE PROCEDURE `heli`.`prodtest` ()
BEGIN
  /*局部变量的定义 declare*/
  declare pid varchar(45) default '';
  declare pq int default 0;
  declare pk double default 0.0;
  declare cur1 CURSOR FOR SELECT pro ......

mysql数据库远程登录权限的问题

昨天用脚本连接数据库时出现了用户登录被拒绝的提示,当然是远程连接Mysql。从网上查查发现是没有远程登录的权限。用时
用:grant all on *.* to 'user'@'192.168.XX.XX' identified by 'password'; 
在使用这个密令前首先要用root用户登录到需要远程访问的数据库上,然后在修改权限。 ......

带你深入了解MySQL语句优化的基本原则


 
 
MySQL语句优化的基本原则:
◆1、使用索引来更快地遍历表。
缺省情况下建立的索引是非群集索引,但有时它并不是最佳的。在非群集索引下,数据在物理上随机存放在数据页上。合理的索引设计要建立在对各种查询的分析和预测上。一般来说:
a.有大量重复值、且经常有范围查询( > ,< ,> =,& ......

MySQL 严格模式 sql_mode

虽然说我们尽量在写程序的时候控制插入到数据库的数据,而不要用数据库去判断数据的对错,但是有时候为了方便还是需要数据库自身的容错能力来帮助我们达到目的的。举例说明:
创建如下数据表
CREATE TABLE `book` (
  `id` int(11) default NULL,
  `num` int(11) unsigned default NULL
) ENGINE=InnoDB DE ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号