mysqldump with there where clause

ive seen the examples of using "where" clause when the fieldname = a numeric value...ie: salesID = 109 ---that works great. returns all the data specified.

where i'm having issues is when i try to use an alphanumeric value...

ie:

mysqldump -h localhost -u jsmith --password=MyPassw0rd --no-create-info --where='sales_person'='Gary' database tablename;

i get nothing....i have a feeling it may be the quotes but ive tried everything and either get a parse error or no results.

any ideas? thx


nriddockAsked:
Who is Participating?
 
todd_farmerCommented:
No - it works for me.  Check the output below - the first run was executed without any --where parameter and includes all 4 rows.  The second includes a --where=name='test2' parameter, and includes only the corresponding row.

C:\Documents and Settings\Todd>mysqldump -uroot -pxxxxxx test tablea
-- MySQL dump 10.10
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version       5.0.18-nt

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0
*/;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `tablea`
--

DROP TABLE IF EXISTS `tablea`;
CREATE TABLE `tablea` (
  `id` int(11) default NULL,
  `name` varchar(10) NOT NULL default '',
  PRIMARY KEY  (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tablea`
--


/*!40000 ALTER TABLE `tablea` DISABLE KEYS */;
LOCK TABLES `tablea` WRITE;
INSERT INTO `tablea` VALUES (1,'test1'),(2,'test2'),(3,'test3'),(4,'test4');
UNLOCK TABLES;
/*!40000 ALTER TABLE `tablea` ENABLE KEYS */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;


C:\Documents and Settings\Todd>mysqldump -uroot -pxxxxxx --where=name='test2' te
t tablea
-- MySQL dump 10.10
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version       5.0.18-nt

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0
*/;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `tablea`
--

DROP TABLE IF EXISTS `tablea`;
CREATE TABLE `tablea` (
  `id` int(11) default NULL,
  `name` varchar(10) NOT NULL default '',
  PRIMARY KEY  (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tablea`
--
-- WHERE:  name='test2'


/*!40000 ALTER TABLE `tablea` DISABLE KEYS */;
LOCK TABLES `tablea` WRITE;
INSERT INTO `tablea` VALUES (2,'test2');
UNLOCK TABLES;
/*!40000 ALTER TABLE `tablea` ENABLE KEYS */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
0
 
todd_farmerCommented:
Did you try this:

mysqldump -h localhost -u jsmith --password=MyPassw0rd --no-create-info --where=sales_person='Gary' database tablename;
0
 
nriddockAuthor Commented:
yep...it echoes the query but returns no results...is it possible that mysqldump only works  w/ numeric values?
0
 
campbelcCommented:
Notice in your example you have tick marks around 'sales_person' take out the tick marks and try again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.