Category Archives: Coding

CMS Made Simple MySQL Error: #1044 – Access denied for user ‘foo’@'%’ to database ‘bar’

CMS Made SimpleToday, I was helping to move a CMS Made Simple site from one webhost to another. It seemed easy enough. I was provided a database dump and copy of the files. It should have been just a matter of importing the database dump with phpmyadmin, scping the files to the new host, editing the config.php, clearing the cache, and refreshing the browser. Right, right? Of course not.

The export of the original tables from MySQL were pretty standard: drop the table if it exists, recreate it, lock it, populate it, unlock it:

DROP TABLE IF EXISTS `cms_additional_htmlblob_users`;
CREATE TABLE `cms_additional_htmlblob_users` (
  `additional_htmlblob_users_id` INT(11) NOT NULL DEFAULT '0',
  `user_id` INT(11) DEFAULT NULL,
  `htmlblob_id` INT(11) DEFAULT NULL,
  PRIMARY KEY  (`additional_htmlblob_users_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `cms_additional_htmlblob_users`
--

LOCK TABLES `cms_additional_htmlblob_users` WRITE;
/*!40000 ALTER TABLE `cms_additional_htmlblob_users` DISABLE KEYS */;
INSERT INTO `cms_additional_htmlblob_users` (`additional_htmlblob_users_id`, `user_id`, `htmlblob_id`) VALUES (6,1,5),(15,1,1);
/*!40000 ALTER TABLE `cms_additional_htmlblob_users` ENABLE KEYS */;
UNLOCK TABLES;

At the new webhost, in phpmyadmin, when importing the SQL, I kept getting the following error:

LOCK TABLES  `cms_additional_htmlblob_users` WRITE ;
MySQL said:
#1044 - Access denied FOR USER 'foo'@'%' TO DATABASE 'bar'

How can I not have the permission to lock tables? So I wanted to figure out if this lock really was the problem. Opening up the original SQL dump in Notepad++, I wanted to find the LOCK TABLES lines and remove them, and the corresponding UNLOCK TABLES. Now, there are way too many tables, so removing the LOCK TABLES by hand is a serious PITA.

Good thing Notepad++ supports regular expression in search. Use this to find all the LOCK TABLES:

LOCK\sTABLES\s`([a-zA-Z0-9_\-\.]+)`\sWRITE;

and replace with nothing. You can find UNLOCK TABLES; directly and remove them.

Turns out after doing that, the SQL imported just fine. So that meant the stupid webhost didn’t allow LOCK TABLES access for the user. Why would you not let users lock their own tables? Plain retarded. There was nothing really wrong with the SQL, just a retarded host.

Thankfully the client got wise and moved to a better host where we had no such problems.

PHP: money_format and setLocale in Mac OS X vs Ubuntu

I had started working on a PHP project on my Macbook, which is running OS X Snow Leopard. With MAMP installed, I started plugging away. One of the requirements of the project was to display prices. Most users of the site would be in the US, so it was determined the currency should show up like $123.45.

On the Mac,

setlocale(LC_MONETARY, 'en_US');

worked perfectly fine.

To get the application ready, we decided to try it out on a test environment running Ubuntu 9.10 (don’t ask why its running Ubuntu 9.10).

Oddly, currency showed up like 123.45, without the dollar sign.

We thought maybe the ‘en_US’ locale wasn’t installed on the machine. To check, we did:

testme@meg:~$ locale -a
C
en_AG
en_AU.utf8
.
.
.
en_US.utf8
en_ZA.utf8
en_ZW.utf8
POSIX

Oops, in Ubuntu, its ‘en_US.utf8′. Doing a

setlocale(LC_MONETARY, 'en_US.utf8');

now allows money_format to work properly.

Ubuntu 10.04 & Node.js – wscript:138: error: could not configure a cxx compiler!

Wanting to learn more about node.js, I grabbed the latest stable branch of the source code and tried to install it on my Ubuntu 10.04 dev box. Simply doing a ./configure returned the following:

nali@nali-desktop:~/dev/nodejs/node-v0.2.6$ ./configure
Checking for program g++ or c++          : not found
Checking for program icpc                : not found
Checking for program c++                 : not found
/home/nali/dev/nodejs/node-v0.2.6/wscript:138: error: could not configure a cxx compiler!

Oh oops, no compiler has been installed. There are a couple different ways to proceed: (1) either install only the packages needed, or (2) wuss out and install build-essentials which will load all the necessary packages and some extra ones for general development. I prefer to wuss out, so I do:

nali@nali-desktop:~/dev/nodejs/node-v0.2.6$ sudo apt-get install build-essential

After all that installs, I try ./configure again, only to get:

Checking for program g++ or c++          : /usr/bin/g++
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for g++                         : ok  
Checking for program gcc or cc           : /usr/bin/gcc
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for gcc                         : ok  
Checking for library dl                  : yes
Checking for openssl                     : not found
Checking for function SSL_library_init   : not found
Checking for header openssl/crypto.h     : not found
/home/nali/dev/nodejs/node-v0.2.6/wscript:195: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are installed. Use configure --without-ssl to disable this message.

Bah, the SSL packages haven’t been installed yet. Do a:

nali@nali-desktop:~/dev/nodejs/node-v0.2.6$ sudo apt-get install libssl-dev

And then you can do a ‘make; sudo make install; make test’ to get it all running.

Mac OS X Perl: Can’t locate Config/IniFiles.pm Error

Perl Screenshot

Perl Screenshot

I ran into an interesting Mac OS X Perl issue the other day. Since @runlevelmedia hosts websites for clients, its a good idea to have a backup strategy. Hoping and prayer is not really strategy.

We have been working on updating our backup plan to make it more efficient. Basically, the script could be run from different machines, so we have multiple copies as a starting point.

Testing out the script on my Macbook threw me for a surprise. Apparently, I mostly use the basic Perl modules pre-installed with Mac OS X and I’d never run across any issues.

jeebus:~ nali$ ./backup.pl --config testconfig.ini
Can't locate Config/IniFiles.pm in @INC (@INC contains: /Library/Perl/Updates/5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10.0 .) at ./backup.pl line 3.
BEGIN failed--compilation aborted at ./backup.pl line 3.

(Yes, my Macbook name is jeebus). Quick Googling found people complaining about the Perl version installed by Mac OS X. The problem is that its not the best idea to yank out the pre-installed version because a lot of apps and systems related processes expects it all work in a certain way. One example I saw was how iTunes used a string comparison behavior that got changed in the more recent versions of Perl. So lots of folks end up installing a bunch of different versions of Perl, which is beyond confusing and unmanageable.

Turns the following command makes it pretty easy to install specific CPAN modules:

sudo perl -MCPAN -e 'install Config::IniFiles'

Another option is to kick off a CPAN shell and install that way:

sudo perl -MCPAN -e 'shell'
Terminal does not support AddHistory.
cpan shell -- CPAN exploration and modules installation (v1.9205)
ReadLine support available (maybe install Bundle::CPAN or Bundle::CPANxxl?)
cpan[1]> install Config::IniFiles
CPAN: Storable loaded ok (v2.18)
Going to read /Users/nali/.cpan/Metadata
....

That’s it!

Atlanta Lions Club
Atlanta Web Design