database
Upgrading to Lenny
by gregs on Mar.09, 2010, under *nix, MySQL, apache, debian, linode
It's been while since I attended to my VPS, I decided to spend some time last night upgrading my distribution from Etch to Lenny. This is normally a moment where your heart sinks as quite a few things do tend to go belly up, but I am happy to report that I only came across some minor issues and these were resolved in minutes as opposed to hours.
- MySQL : failed to start, complaining about:
CODE:
-
/etc/init.d/mysql: ERROR: Using expire_logs_days without log_bin crashes
-
the server. See README.Debian.gz
Commenting out the expire_logs_days in the my.cnf file allowed me to restart MySQL.
-
- After the upgrade of Apache, my virtual hosts weren't working. A quick search via Google pointed me to this post - a quick edit of all of my host files and it was all working again.
- the php-mysql connector somehow hadn't been upgraded/installed so a quick
CODE:
-
apt-get install php5-mysql
fixed that problem.
-
- OpenBD : the only thing that remains broken was my tomcat5.5 Open BD install. Tomcat was working fine but Open BD refused to start up complaining about :
CODE:
-
javax.servlet.ServletException: Open BlueDragon Engine Failed to initialise tags: java.awt.Color
Since I am not really using it, it's not that important, but at some stage I'd like to get it working again. If you have any suggestions, please leave a comment.
-
SQL to XML
by gregs on Aug.29, 2007, under MS SQL
Just came across this neat trick that uses SQL to generate XML on the fly:
-
DECLARE @x xml
-
SET @x=(select geoAreaCode
-
, geoLevelCode
-
, geoLevelId
-
, geoAreaId
-
from tbl_geoLevel
-
where uuid =
-
for xml raw('geoArea'), root('geoAreas'), type)
-
SELECT @x AS geoAreaInfo
The above will create an XML structure that has a root value of geoAreas and child elements of geoArea for each row found.
Beyond SQL injection attacks
by gregs on Nov.23, 2006, under MS SQL, MySQL
Courtesy of Slashdot a reminder that you should also worry about other types of injection attacks. Don't you just wish that everybody would play nice?
UPDATE
In a similar vein, Nadav Samet covers off in more detail Cross Site Scripting attacks, how they work and what you can do to protect your site.
LogParser
by gregs on Nov.23, 2006, under MS SQL, log, parse
Charlie Arehart has a handy little article published in this months CFDJ on using Microsoft's Log Parser tool, which allows you to write SQL like statements against your CFMX log files. Couldn't find a publicly accessible link, but if you keep an eye on his articles page, I am sure he'll update it as soon as it is available.
Update
Charlie dropped me a note last week to let me know that the article can be found on-line here
AUTO INCREMENT
by gregs on Jun.29, 2006, under MySQL
Since the MySQL Query Browser on my Mac refused to let me set a field as auto increment through the GUI, here's how you can using SQL change an existing column to use auto_increment:
-
ALTER TABLE `aggregatedWeekly` CHANGE `Id` `Id` INT( 6 ) UNSIGNED NOT NULL AUTO_INCREMENT
UPDATE
I have also recently found out that the following works just as well:
CFMX – MSDE connection refused error
by gregs on Dec.16, 2005, under ColdFusion, MS SQL
I just started using MSDE for local development again and after creating my first DSN through the ColdFusion administrator I encountered the following problem:
-
# Connection verification failed for data source: SMS
-
java.sql.SQLException: [Macromedia][SQLServer JDBC Driver]Error establishing socket. Connection refused: connect
-
The root cause was that: java.sql.SQLException: [Macromedia][SQLServer JDBC Driver]Error establishing socket. Connection refused: connect
First thing I checked (well second after making sure I had provided the right connection details) was to see if anything was listening port on port 1433 by using the handy "netstats -a" command. And there wasn't, so a quick Google search turned up this gem from Robi Sen. Sadly this tool didn't help me as apparently my version didn't need it, but a comment did point me to a another link. But sadly it didn't help me either, but the comment did give me an idea. When I went to check my network set up for MS SQL server, sure enough TCP/IP was not listed... What followed was a moment of banging my head sharply on the table.
Right changes applied, restarted the server, verify connection and...
-
Connection verification failed for data source: SMS
-
java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Login failed for user 'hermes'. Reason: Not associated with a trusted SQL Server connection.
-
The root cause was that: java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Login failed for user 'yourUsername'. Reason: Not associated with a trusted SQL Server connection.
Well this one only took a few seconds to fix: Windows Authentication only was enabled! Simply open the properties of your server once more, check the security tab and you should see that the option for Windows Authentication is selected. Just change that to SQL server and Windows and you are ready to go...
I guess this is very much a case of damned if you do and damned if you don't for Microsoft as they seemed to have tightened up the security for MS SQL server (I won't even go into the nuisance of trying to install MSDE and being prompted to set an SA password before starting with no indication how to do so), but surely we should be given the option at install time to set these things? Or maybe it's just the MSDE?
LIKE and Oracle
by gregs on Oct.21, 2005, under Oracle, database
I never spotted this before but the LIKE operator is case sensitive! Which was skewing my search results quite severely. The work around is to put everything into upper case, both the values in the column you are performing the search against as well as the value of the varibale you are searching for.
-
SELECT col1, col2, col3
-
FROM table
-
WHERE UPPER(col4) LIKE '%UPPER(yourValue)%'
Updates from a select
by gregs on Oct.20, 2003, under MS SQL
I have been doing a lot more database based work recently and have learned one or two pretty useful techniques. Here is an extremely useful one: Running an update based on a select statement.
In the past whenever I could have wanted to do a bulk update on a table based on certain criteria, I would have run a select statement to retrieve a bunch of columns first and then programmatically looped over the result set and updated the values. But there is a much, much easier and way more efficient way of doing this. Just take a quick look at the statement below.
-
UPDATE someUsersTable
-
SET someUsersTable.EmailPrivate = someOtherJoinTable.PublicEmail
-
FROM someUsersTable INNER JOIN someOtherJoinTable ON someUsersTable.userID = someOtherJoinTable.userID
-
WHERE (tbl_Users.userEmailPrivate = '')
It was constructed very much the way I would have normally approached the problem. First I wrote the select statement in Query Analyzer, i.e. SELECT * FROM FROM someUsersTable INNER JOIN someOtherJoinTable ON someUsersTable.userID = someOtherJoinTable.userID WHERE (tbl_Users.userEmailPrivate = ''). This gave me the result set I wanted to work with. Next I quite simply removed the SELECT statement replaced it with a corresponding UPDATE statement. So easy when you know how and the performance should be way better than before hand, because rather than making multiple trips back and forth to the database server from the web application it's all handled by the database server in one swoop!
Accessing a dB on a remote server
by gregs on Oct.18, 2000, under ColdFusion, database
Some of the information we wanted to publish on my previous company's intranet was residing on databases that weren't on the main web server. This initially caused a little headache as we really needed to access that data on the remote NT server and publish it. So how do you get around that problem??
Well the solution to that problem turns out to be incredibly simple. I maped a drive to our web server to the share where the database was held. Then I started up the Cold Fusion Administrator and created a datasource for that database (Db) and went through the process in the normal manner. You'll notice that once you browse for that Db that you can't see the mapped drive. So go back to the previous screen and enter the path manually, something like this:
[code]
{drive letter}\:{share name}\{directory or file name}
[\code]
That's pretty much it. You can now safely create the datasource. Should the Verification process fail go to the advanced properties section of the datasource properties, you may have to specify a user account with sufficient permissions to access that share, i.e. create a CF service account with sufficient permissions and that should do the trick.
Configuring MyODBC on NT
by gregs on Oct.17, 2000, under MySQL
This is effectively part II of configuring MySQL for NT. With the help of this document you will be able to access your MySQL database server from other Windows applications (e.g. Cold Fusion). Right so let's get started. We shall begin with installing MyODBC (a copy of which can be obtained from here http://www.mysql.com/downloads/api-myodbc.html).
Installing MyODBC is straightforward. Unzip the downloaded file and click on the setup.exe file and simply follow the installation prompts. For starters just keep accepting the default settings if you are unsure of any options.
OK, now we are ready to add a MySQL datasource. You have to do this through ODBC datasources in the Control Panel. Please note: if you were planning on using the Cold Fusion Administrator, you can't. You have to go through the Control Panel to initially configure the datasource. Once setup you can modify your MySQL datasources through the Cold Fusion Administrator. So go ahead and fire up your ODBC manager.
Once open, go to the the system DNS tab and select Add.... From the list of available drivers select MySQL and click Finish. This should fire up a dialogue with a whole bunch of fields. Listed below is a sample entry:
-
Windows DNS name: mydsn
-
MySQL host (name or ip): 127.0.0.1
-
MySQL database name: mydatabase
-
User: myusername
-
Password: mypassword
Things to bear in mind are: from my personal experience, I found that it's best to keep windows DSN and database name in lower case. Specifying the IP address works, I have had problems using the host name setting. As for the username and password, make sure that you use those properties that you set to the database you created. I.e. if you don't require a logon to connect to that database, then leave the fields blank. Else enter the username and password assigned to that database (the default root account will work well, but is contentious for security reasons).
Well we are done you should know have configured your system to connect to a MySQL database via ODBC.