You are currently browsing the archives for the MySQL category.

Archive for the ‘MySQL’ Category

MySQL server version for the right syntax to use near ‘USING BTREE

星期二, 7月 6th, 2010

mysqldump 经常会遇到版本不一致引起的导入到处问题, 本文给出了参考解决方法。

http://www.magento-vietnam.com/magento-tips-tricks/magento-database-import-error/
Magento Database Import Error

ERROR 1064 (42000) at line 382: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘USING BTREE,
KEY `FK_ATTRIBUTE_VARCHAR_ENTITY` (`entity_id`),
KEY `FK_CATALO’ at line 9

The reason behind this is that there is an inconsistency in the way the export syntax was being handled as I imported into the staging environment (which evidently has a different MySQL version running). Thus, the staging site was expecting different syntax for the following:


– Table structure for table `catalog_category_entity_varchar`

DROP TABLE IF EXISTS `catalog_category_entity_varchar`;
CREATE TABLE `catalog_category_entity_varchar` (
`value_id` int(11) NOT NULL AUTO_INCREMENT,
`entity_type_id` smallint(5) unsigned NOT NULL DEFAULT ‘0′,
`attribute_id` smallint(5) unsigned NOT NULL DEFAULT ‘0′,
`store_id` smallint(5) unsigned NOT NULL DEFAULT ‘0′,
`entity_id` int(10) unsigned NOT NULL DEFAULT ‘0′,
`value` varchar(255) NOT NULL DEFAULT ”,
PRIMARY KEY (`value_id`),
UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`) USING BTREE,
KEY `FK_ATTRIBUTE_VARCHAR_ENTITY` (`entity_id`),
KEY `FK_CATALOG_CATEGORY_ENTITY_VARCHAR_ATTRIBUTE` (`attribute_id`),
KEY `FK_CATALOG_CATEGORY_ENTITY_VARCHAR_STORE` (`store_id`)
) ENGINE=InnoDB AUTO_INCREMENT=697 DEFAULT CHARSET=utf8;

As a rule of thumb, one can either

  • (1) head over to the MySQL Developer Documentation for syntax reference
  • (2) or simply check out a recent Magento export from the server they are trying to import into and determine how the “USING BTREE” statement was handled. Likewise, I simply removed the following:

UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`) USING BTREE,

and replaced it with this:

UNIQUE KEY `IDX_BASE` USING BTREE (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`),

Hope this helps someone who is experiencing the same error and spending way too much time trying to understand the incompatible syntax.

分享家:Addthis中国

ubuntu 10.01 restart mysql

星期日, 5月 9th, 2010

yaozer@local:~$ sudo /etc/init.d/mysql restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the restart(8) utility, e.g. restart mysql
mysql start/running, process 18095
yaozer@local:~$ sudo restart mysql
mysql start/running, process 18137

分享家:Addthis中国

MySQLTuner High-performance MySQL optimization script

星期三, 2月 24th, 2010

http://blog.mysqltuner.com/download/

wget mysqltuner.pl
perl mysqltuner.pl
分享家:Addthis中国

连接远程mysql数据库服务器慢的原因

星期六, 8月 15th, 2009

新搭建的web server + db server 很不稳定, 访问特别慢, 而且经常连接不上。 查看运行结果, 每小时连接失败的次数有几十次,但其他参数均正常。配置怎么改都没有用, 后来发现phpmyadmin  process一栏里面把web server过来的连接认为是 unauthenticated user,  于是从这个点着手, 找到了原因。

解决方法:  把 web server 的 IP 放入db server 的 /etc/hosts 里面。

综合网上各类资料, yaozer 简单总结一下原因: MySQL 默认会进行DNS解析(写明了IP也还要去解析一下,为的是得到主机名,然后可以授权该主机名而不用写明IP), 而这个DNS解析需要调用系统函数,如果这些系统函数有问题, 连接就会受影响。 把 web server 的 IP 放入db server 的 /etc/hosts 里面, 采用本地DNS解析来解决这个问题, 是最上乘之选。使用skip-name-resolve的方式后,只能全部输IP访问了,会让 localhost 没法访问。

http://www.unixresources.net/linux/clf/db/archive/00/00/34/77/347701.html#article347701   里面讨论了类似的情况,复制部分:

  • 我的一台服务器RedHat7.3,上面跑了个Mysql服务。一直以来服务正常。可是昨天,我突然不能远程连接 我的数据库服务器(mysql)了。后来我把自己机器的ip加入/etc/hosts就可以,但是取消/etc/hosts IP这一行就不可以连接了,显示“lost connection to mysql server during query”
  • 算起来就是前几天更新了几个包而已,glibc等,应该跟mysql没关系的。你的临时解决方法我也试过了,可以暂时顶住。
  • 首先谢谢大家的关心,这个问题已经有很多人遇到,只是我们遇得比较早。总体上讲都是由于系统得某些升级造成的。我经过多方查证和收集资料,咨询。得到这个解决方案。不敢独享,还望各位给我指证,谢谢!解决方案:
    在Mysql服务启动脚本/etc/rc.d/init/mysqld 里面的start里面加入”–skip-name-resolve”参数,禁止反相IP解析。问题得到解决。
  • 接到redhat发布的errata通告了,原来是glibc库的问题。通告还专门指出了mysql会出错。

附: MYSQL远程连接速度慢的解决方法的相关资料

http://bbs.lihuasoft.net/thread-10904-1-1.html
http://tech.e800.com.cn/articles/2009/630/1246332746740_1.html
http://www.xishuiw.com/info/2009-3/2009-3-16-16759.htm
http://doc.linuxpk.com/66944.html
http://be-evil.org/post-40.html   该文提到了 Mysql DNS 的细节

分享家:Addthis中国

mysql数据库备份与还原zz

星期二, 8月 11th, 2009

备份MySQL数据库的命令

mysqldump -hhostname -uusername -ppassword databasename > backupfile.sql

备份MySQL数据库为带删除表的格式
备份MySQL数据库为带删除表的格式,能够让该备份覆盖已有数据库而不需要手动删除原有数据库。

mysqldump -–add-drop-table -uusername -ppassword databasename > backupfile.sql

直接将MySQL数据库压缩备份

mysqldump -hhostname -uusername -ppassword databasename | gzip > backupfile.sql.gz

备份MySQL数据库某个(些)表

mysqldump -hhostname -uusername -ppassword databasename specific_table1 specific_table2 > backupfile.sql

同时备份多个MySQL数据库

mysqldump -hhostname -uusername -ppassword –databases databasename1 databasename2 databasename3 > multibackupfile.sql

仅仅备份数据库结构

mysqldump –no-data –databases databasename1 databasename2 databasename3 > structurebackupfile.sql

备份服务器上所有数据库

mysqldump –all-databases > allbackupfile.sql

还原MySQL数据库的命令

mysql -hhostname -uusername -ppassword databasename < backupfile.sql

还原压缩的MySQL数据库

gunzip < backupfile.sql.gz | mysql -uusername -ppassword databasename

将数据库转移到新服务器

mysqldump -uusername -ppassword databasename | mysql –host=*.*.*.* -C databasename
来源: http://www.lihaixin.com/2008/12/mysql-database-backup-and-restore-order-994.html
分享家:Addthis中国

ubuntu安装lamp的最简单方法

星期日, 7月 5th, 2009

ubuntu 如何搭建 lamp ?那还不容易, apache2, php5, mysql-server 之类的装一下不就可以了吗? 但是有时候也会遇到一些问题, 比如ubuntu 9.04上面安装mysql-server5.1是有些问题的。
怎么安装最简单呢? 答案是这样的:

sudo apt-get install lamp-server^

别忘了最后面那个 ^ , 这条命令和一般命令不一样哦, 原理见此处:https://help.ubuntu.com/community/Tasksel

分享家:Addthis中国

利用mysqlcheck优化,维护MySQL表

星期日, 6月 28th, 2009

mysqlcheck -Aoqp

去看看结果有没有改善吧!

分享家:Addthis中国

使用mysqlreport优化MySQL server

星期日, 6月 28th, 2009

mysqlreport 是一个很好的MySQL 工具, http://hackmysql.com/mysqlreportguide

参考 :

http://www.phpfreaks.com/forums/index.php?topic=183569.0

分享家:Addthis中国

tuning-primer.sh : Unable to log into socket

星期日, 6月 28th, 2009

tuning-primer.sh 是个蛮有名的MySQL优化工具, 下载地址:http://day32.com/MySQL运行时运行时/

运行时有时候会出现以下错误:

# ./tuning-primer.sh

- INITIAL LOGIN ATTEMPT FAILED -

Testing Stored for passwords:- RETRY LOGIN ATTEMPT FAILED -

Could not auto detect login info!

Do you have your login handy ? [y/N] : y
User: root
Password:
Would you like me to create a ~/.my.cnf file for you? [y/N] : n
- FINAL LOGIN ATTEMPT FAILED -

Unable to log into socket: /var/run/mysqld/mysqld.sock

解决办法:

/etc/init.d/mysql stop
pkill -u mysql
rm -f /var/run/mysqld/*
/etc/init.d/mysql start
./tuning-primer.sh

分享家:Addthis中国

上手难!这一点postgresql要学习MySQL啊!

星期二, 12月 2nd, 2008

撇开两者的其他方面,首先是要让它们跑起来, MySQL + PhpMyAdmin 一装, 不看入门教程就把基本的环境搭好了。 而postgresql呢, 我一个学计算机, 第一次配好竟然累计用了差不多5个小时, 关键是找不到很好的入门资料,官方的安装指导毫无实用价值,其他资料也少有击中要害的。 引入了psql, 就该强调一下;运行一个命令,提示信息寥寥数语, 也不确定结果如何; 显示所有数据库, 搜了半天才找到; pgAdmin 3 是需要图形界面的, web的管理软件有没有?
等等等等, pg对第一次的使用者来说, 上手不容易啊。


sudo -u postgres psql postgres 进入psql 模式后,按 ? 可查看 psql 命令, 要执行命令别忘了加分号; 下面列一些典型的命令:

显示所有数据库
mysql : show databases
psql : l 或者l+

使用某数据库
mysql : use xx
psql : c xx

显示数据库表
mysql : show tables
psql : dt

分享家:Addthis中国