You are here

Add new comment

OpenOffice with MySQL

Setting up MySQL following initial installation:
->mysql mysql -this gets us into mysql
mysql> delete from user where host='localhost' and user='';
mysql> quit

then
-> mysqladmin reload
-> mysqladmin -u root password my_password_here

now we reconnect to mysql
-> mysql -h localhost -u root -p
mysql> grant all priveleges on *.* to my_user_name@localhost identified by 'my_user_password';

Now we have a user with full privileges on the database.

To set up the connection between MySQL and OpenOffice I used myODBC, which has a config program called as "ODBCConfig". Run this as root (in KDE use alt-F2 and select options to run as root). Then set a driver and a user or system DSN

On a SuSE 9.1 system,
The driver is: /usr/lib/unixODBC/libmyodbc3-3.51.06.so
The setup is /usr/lib/unixODBC/libodbcmyS.so.1

In OpenOffice, under Tools, Data Source, we can then select the ODBC database type, and then select the available data sources.

To make sure we can edit tables, there is a macro that needs to be run (see under "more").
I found the following sites helpful in getting to this point:

Sourceforge:setting up OOo with MySQL and Openoffice.org howto IgnoreDriverPrivilegesEnter and run this as a macro in OpenOffice with Tools-Macros, and enter the name of your datasource (the one you entered in OpenOffice Data Sources)

REM ***** BASIC *****

Option Explicit

Sub Main
Dim sDataSourceName as String
sDataSourceName = InputBox( "Please enter the name of the data source:" )
IgnoreDriverPrivileges(sDataSourceName )
End Sub

Sub IgnoreDriverPrivileges(sDataSourceName as String )
' the data source context (ehm - the service name is historical :)
Dim aContext as Object
aContext = createUnoService( "com.sun.star.sdb.DatabaseContext" )

If ( Not aContext.hasByName( sDataSourceName ) ) Then
MsgBox "There is no data source named " + sDataSourceName + "!"
Exit Sub
End If

' the data source
Dim aDataSource as Object
aDataSource = aContext.getByName( sDataSourceName )

' append the new IgnoreDriverPrivilegesflag
Dim bFlag as Boolean
bFlag = TRUE
Dim aInfo as Variant
aInfo = aDataSource.Info
aInfo = AddInfo( aInfo, "IgnoreDriverPrivileges", bFlag )

' and write back
aDataSource.Info = aInfo
' flush (not really necessary, but to be on the safe side :)
aDataSource.flush
End Sub

Function AddInfo( aOldInfo() as new com.sun.star.beans.PropertyValue,sSettingsName as String, aSettingsValue as Variant ) as Variant
Dim nLower as Integer
Dim nUpper as Integer
nLower = LBound( aOldInfo() )
nUpper = UBound( aOldInfo() )

' look if the setting is already present
Dim bNeedAdd as Boolean
bNeedAdd = TRUE

Dim i As Integer
For i = nLower To nUpper
If ( aOldInfo( i ).Name = sSettingsName ) Then
aOldInfo( i ).Value = aSettingsValue
bNeedAdd = FALSE
End If
Next i

' allocate the new array
Dim nNewSize as Integer
nNewSize = ( nUpper - nLower )
If bNeedAdd Then nNewSize = nNewSize + 1
Dim aNewInfo( nNewSize ) as new com.sun.star.beans.PropertyValue

' copy the elements (a simply copy does not work in Basic)
For i = nLower To nUpper
aNewInfo( i ) = aOldInfo( i )
Next i

' append the new setting, if necessary
If ( bNeedAdd ) Then
aNewInfo( nUpper + 1 ).Name = sSettingsName
aNewInfo( nUpper + 1 ).Value = aSettingsValue
End If

AddInfo = aNewInfo()
End Function

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer