Anders Karlsson Principal Sales Engineer, MySQL MySQL Embedded - Getting started with libmysqld
Agenda <ul><li>Who am I? (Good question!) </li></ul><ul><li>Why libmysqld? </li></ul><ul><li>What is libmysqld? </li></ul>...
About Anders Karlsson <ul><li>Sales Engineer with Sun / MySQL for 5+ years </li></ul><ul><li>I have been in the RDBMS busi...
Why libmysqld? <ul><li>Libmysqld is compact and fast </li></ul><ul><li>Libmysqld is easily integrated into an application ...
And why NOT libmysqld? <ul><li>Only ONE application can connect at the time! </li></ul><ul><li>No server means less flexib...
What is libmysqld and why is it different? <ul><li>“ Normal” MySQL is a classic client/server based RDBMS </li></ul><ul><u...
What is libmysqld and why is it different? <ul><li>MySQL in Client / Server configuration </li></ul><ul><ul><li>MySQL Serv...
What is libmysqld and why is it different? <ul><li>Libmysqld is a SQL database layer tightly integrated with the applicati...
What is libmysqld and why is it different? <ul><li>Libmysqld configuration </li></ul><ul><ul><li>The Application IS the se...
So where do I find libmysqld? <ul><li>Libmysqld is part of the usual MySQL distribution </li></ul><ul><li>Just download th...
Building libmysqld applications <ul><li>Develop applications in C </li></ul><ul><ul><li>Add calls to mysql_library_init() ...
The libmysqld API <ul><li>VERY similar to the MySQL C API </li></ul><ul><ul><li>Does NOT implement the MySQL Protocol! </l...
The mysql_library_init() function <ul><li>Initializes the MySQL internal server </li></ul><ul><li>Passes parameters to the...
The mysql_library_init() parameters <ul><li>Argument count (argc) </li></ul><ul><li>Arguments (argv) – Like the parameters...
<ul><li>static char *server_options[] = { &quot;mysql_test&quot;, &quot;--datadir=C:/mydata&quot;, NULL}; </li></ul><ul><l...
Configuring a libmysqld application <ul><li>Use a my.cnf file </li></ul><ul><ul><li>Set  server_options  as per the previo...
Dynamic linking of a libmysqld application <ul><li>As a shared object / DLL </li></ul><ul><ul><li>An import library is pro...
Static linking of a libmysqld application <ul><li>As a static library </li></ul><ul><ul><li>The libmysqld library is linke...
Linking a libmysqld application <ul><li>Note that dynamic linking does NOT necessarily allow you to update libmysqld by ju...
Managing libmysqld data <ul><li>Data format are the same for libmysqld as it is for the MySQL Server mysqld </li></ul><ul>...
Managing libmysqld data <ul><li>Offline tools for mysqld data may be used on libmysqld data </li></ul><ul><ul><li>myisampa...
Libmysqld demo! <ul><li>The following demo application is available </li></ul><ul><ul><li>On sourceforge: http://sourcefor...
Limitations of libmysqld <ul><li>No replication </li></ul><ul><li>No events </li></ul><ul><li>InnoDB is single threaded </...
Libmysqld performance 100.000 operations each, time in average after several runs Note:  This is very far from a scientifi...
Libmysqld performance <ul><li>So does this mean that libmysqld is faster than mysqld? </li></ul><ul><ul><li>No, it means t...
Resources and contacts <ul><li>Email me at: [email_address] </li></ul><ul><li>Read my blog at: http://karlssonondatabases....
Questions? [email_address]
Upcoming SlideShare
Loading in...5
×

Libmysqld Introduction

5,505
-1

Published on

An introduction to MySQL Embedded with libmysqld

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
  • Good, just what I need.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
5,505
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
24
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Libmysqld Introduction

  1. 1. Anders Karlsson Principal Sales Engineer, MySQL MySQL Embedded - Getting started with libmysqld
  2. 2. Agenda <ul><li>Who am I? (Good question!) </li></ul><ul><li>Why libmysqld? </li></ul><ul><li>What is libmysqld? </li></ul><ul><ul><li>What is MySQL Emmbedded? And is it different from libmysqld? </li></ul></ul><ul><li>Programming with libmysqld </li></ul><ul><ul><li>API, Samples etc. </li></ul></ul><ul><li>Limitations of libmysqld </li></ul><ul><li>Questions? Answers? </li></ul>
  3. 3. About Anders Karlsson <ul><li>Sales Engineer with Sun / MySQL for 5+ years </li></ul><ul><li>I have been in the RDBMS business for 20+ years </li></ul><ul><li>I have worked for many of the major vendors and with most of the vendor products </li></ul><ul><li>I’ve been in roles as </li></ul><ul><ul><li>Sales Engineer </li></ul></ul><ul><ul><li>Consultant </li></ul></ul><ul><ul><li>Porting engineer </li></ul></ul><ul><ul><li>Support engineer </li></ul></ul><ul><ul><li>Etc. </li></ul></ul><ul><li>Outside MySQL I build websites (www.papablues.com), develop Open Source software (MyQuery, ndbtop etc), am a keen photographer and drives sub-standard cars, among other things. Also, I am pushing for ZFS to become GPL: http://www.makezfsgpl.com </li></ul>
  4. 4. Why libmysqld? <ul><li>Libmysqld is compact and fast </li></ul><ul><li>Libmysqld is easily integrated into an application </li></ul><ul><li>Application installation is MUCH easier </li></ul><ul><ul><li>No separate server to install or run </li></ul></ul><ul><ul><li>No need to run as service or daemon </li></ul></ul><ul><li>Low hardware requirements </li></ul><ul><li>Zero maintenance </li></ul><ul><li>MySQL hidden from end user </li></ul>
  5. 5. And why NOT libmysqld? <ul><li>Only ONE application can connect at the time! </li></ul><ul><li>No server means less flexibility </li></ul><ul><li>Application itself has larger footprint </li></ul><ul><ul><li>Includes both the server and the application </li></ul></ul><ul><li>Certain limitations exist </li></ul><ul><li>No Replication </li></ul><ul><li>No Client / Server connection </li></ul><ul><li>No authentication / security </li></ul><ul><li>More functions must be implemented in the application </li></ul><ul><ul><li>Any mysql Client operations such as dump, restore, check etc. </li></ul></ul>
  6. 6. What is libmysqld and why is it different? <ul><li>“ Normal” MySQL is a classic client/server based RDBMS </li></ul><ul><ul><li>The database server is a separate process from the client application </li></ul></ul><ul><ul><li>The client and the sever communicates using standard networking (typically sockets or TCP/IP) </li></ul></ul><ul><ul><li>The Server may, and again may not, run in a separate hardware environment from the client </li></ul></ul><ul><ul><li>The client talks to the server using a MySQL defined protocol, typically implemented in a client interface or “driver” or Connector </li></ul></ul>
  7. 7. What is libmysqld and why is it different? <ul><li>MySQL in Client / Server configuration </li></ul><ul><ul><li>MySQL Server runs on machine on the network </li></ul></ul><ul><ul><li>Clients communicate with Server using the MySQL Protocol </li></ul></ul><ul><ul><li>Many clients talk to the same server </li></ul></ul>Clients using MySQL Protocol Server Disk
  8. 8. What is libmysqld and why is it different? <ul><li>Libmysqld is a SQL database layer tightly integrated with the application or “client” </li></ul><ul><ul><li>The database and the application runs in the same process space </li></ul></ul><ul><ul><li>No special means of communication is needed as both the application and the database are in the same process, calling MySQL is similar to calling any other library function </li></ul></ul><ul><ul><li>The interface between the Application or client is different, but the exposed component, the API, is the same as with Client / Server MySQL </li></ul></ul><ul><ul><li>Although the API looks the same, the implementation is different! </li></ul></ul>
  9. 9. What is libmysqld and why is it different? <ul><li>Libmysqld configuration </li></ul><ul><ul><li>The Application IS the server! </li></ul></ul><ul><ul><li>There is just 1 process </li></ul></ul><ul><ul><li>Data is stored on the local disk </li></ul></ul><ul><ul><li>NOTE: The API for the application is the same, but the implementation is different! There is just one implementation: In C </li></ul></ul><ul><ul><li>All data is local </li></ul></ul><ul><ul><li>Only one “client” </li></ul></ul>Application process libmysqld Client system
  10. 10. So where do I find libmysqld? <ul><li>Libmysqld is part of the usual MySQL distribution </li></ul><ul><li>Just download the MySQL Server and you find </li></ul><ul><ul><li>On Windows : libmysqld is in the Embedded subdirectory, both debug and release versions are available, and in DLL and static builds </li></ul></ul><ul><ul><li>On Linux : libmysqld.a is in the lib subdirectory where MySQL is installed </li></ul></ul><ul><li>Includefiles: </li></ul><ul><ul><li>Use the normal MySQL C API includefiles </li></ul></ul>
  11. 11. Building libmysqld applications <ul><li>Develop applications in C </li></ul><ul><ul><li>Add calls to mysql_library_init() etc. </li></ul></ul><ul><li>Compile as usual </li></ul><ul><li>Link with libmysqld </li></ul><ul><ul><li>Can be linked dynamically or statically </li></ul></ul><ul><ul><li>A dynamic link is easier, just as a dynamic link with the MySQL C Client library is easier </li></ul></ul><ul><li>Set up an option file </li></ul><ul><li>Ship application, possibly the libmysqld shared library and option file </li></ul>
  12. 12. The libmysqld API <ul><li>VERY similar to the MySQL C API </li></ul><ul><ul><li>Does NOT implement the MySQL Protocol! </li></ul></ul><ul><ul><li>Only looks the same, implementation is different! </li></ul></ul><ul><li>Key functions that are different </li></ul><ul><ul><li>mysql_library_init() – Starts the internal “MySQL Server” </li></ul></ul><ul><ul><li>mysql_library_end() – Shuts down the internal “MySQL Server” gracefully </li></ul></ul><ul><ul><li>mysql_thread_init() / mysql_thread_end() </li></ul></ul><ul><ul><li>mysql_options() – Set MYSQL_OPT_USE_EMBEDDED_CONNECTION before connecting </li></ul></ul>
  13. 13. The mysql_library_init() function <ul><li>Initializes the MySQL internal server </li></ul><ul><li>Passes parameters to the server in that process </li></ul><ul><li>Must be passed information on initialization files and sections in those </li></ul><ul><ul><li>No server is already running! </li></ul></ul><ul><ul><li>This means all necessary server parameters needs to be specified! </li></ul></ul><ul><li>This means that this call is mostly different from when NOT using libmysqld! </li></ul><ul><li>MUST be called before mysql_init()! </li></ul>
  14. 14. The mysql_library_init() parameters <ul><li>Argument count (argc) </li></ul><ul><li>Arguments (argv) – Like the parameters to mysqld, the first argument (as in argv[0] beging name of the program) being ignored. </li></ul><ul><li>A list of option file sections to read </li></ul><ul><ul><li>If a -- defaults-file or any other argument with an option file is passed, the config files section specifies whicg sections in this file to read </li></ul></ul><ul><ul><li>The last section name is NULL </li></ul></ul><ul><ul><li>If no option file is passed, this argument may be NULL. </li></ul></ul>
  15. 15. <ul><li>static char *server_options[] = { &quot;mysql_test&quot;, &quot;--datadir=C:/mydata&quot;, NULL}; </li></ul><ul><li>static char *server_groups[] = { &quot;libmysqld_server&quot;, NULL}; </li></ul><ul><li>int main(argc, argv) { MYSQL mysql; </li></ul><ul><li>mysql_library_init(sizeof(server_options)/ sizeof(char *) – 1, server_options, (char **) server_gropus); mysql = mysql_init(NULL); mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL); mysql_real_connect(mysql, NULL, NULL, NULL, &quot;test&quot;, 0, NULL, 0); </li></ul>Initializing a libmysqld application
  16. 16. Configuring a libmysqld application <ul><li>Use a my.cnf file </li></ul><ul><ul><li>Set server_options as per the previous slide, to include --defaults-file=my.cnf </li></ul></ul><ul><ul><li>Note that you must be careful with the path here! </li></ul></ul><ul><ul><li>Set up the my.cnf file </li></ul></ul><ul><li>Or set all options in the application itself </li></ul><ul><ul><li>Set all options in the server_options variable </li></ul></ul>
  17. 17. Dynamic linking of a libmysqld application <ul><li>As a shared object / DLL </li></ul><ul><ul><li>An import library is provided to be linked with your application </li></ul></ul><ul><ul><li>Your application will need to be distributed with the libmysqld shared object / DLL </li></ul></ul><ul><ul><li>Not available on all platforms </li></ul></ul>Application Libmysqld Import Library Libmysqld shared library
  18. 18. Static linking of a libmysqld application <ul><li>As a static library </li></ul><ul><ul><li>The libmysqld library is linked directly into the application </li></ul></ul><ul><ul><li>No additional files needs to be distributed with the application </li></ul></ul><ul><ul><li>The only option on some platforms </li></ul></ul><ul><ul><li>Has a slight performance benefit </li></ul></ul>Application Libmysqld Library
  19. 19. Linking a libmysqld application <ul><li>Note that dynamic linking does NOT necessarily allow you to update libmysqld by just changing the DLL / Shared object </li></ul><ul><ul><li>Typically, an application linked with MySQL version X needs libmysqld version X, even with dynamic linking </li></ul></ul><ul><li>For Windows, I recommed dynamic linking </li></ul><ul><ul><li>Windows static linking is complex, as the static library depends on a particular version of Visual C++ is used </li></ul></ul><ul><li>For Linux, I recommend static linking </li></ul><ul><ul><li>Not the least because that is the only option right now. But it is less problematic than on windows, and has a slight performance advantage </li></ul></ul>
  20. 20. Managing libmysqld data <ul><li>Data format are the same for libmysqld as it is for the MySQL Server mysqld </li></ul><ul><ul><li>Hence: Data that can be freely copied with mysqld can be freely copied with libmysqld </li></ul></ul><ul><ul><li>This relates to most storage engines, but in some cases with limitations </li></ul></ul><ul><li>MyISAM may use compression (which is common) and other MyISAM variations </li></ul><ul><li>Starting a libmysqld application with InnoDB enabled (not using --skip-innodb ) will create InnoDB data and transaction log files, as usual </li></ul>
  21. 21. Managing libmysqld data <ul><li>Offline tools for mysqld data may be used on libmysqld data </li></ul><ul><ul><li>myisampack </li></ul></ul><ul><ul><li>myisamchk </li></ul></ul><ul><ul><li>etc </li></ul></ul><ul><li>Online tools need to be implemented as part of the application </li></ul><ul><ul><li>mysqldump </li></ul></ul><ul><ul><li>mysqlshow </li></ul></ul><ul><ul><li>etc. </li></ul></ul>
  22. 22. Libmysqld demo! <ul><li>The following demo application is available </li></ul><ul><ul><li>On sourceforge: http://sourceforge.net/projects/libmysqlddemo/ </li></ul></ul><ul><ul><li>On MySQL Forge: http://forge.mysql.com/projects/project.php?id=323 </li></ul></ul><ul><li>The application is Windows dialog-based and written in C using the Win32 API </li></ul><ul><li>Should be self contained, except for libmysqld of course, and the language file </li></ul>
  23. 23. Limitations of libmysqld <ul><li>No replication </li></ul><ul><li>No events </li></ul><ul><li>InnoDB is single threaded </li></ul><ul><li>No authentication / authorization </li></ul><ul><li>Single application access </li></ul><ul><ul><li>But that is the whole point of libmysqld </li></ul></ul><ul><li>Only C / C++ </li></ul>
  24. 24. Libmysqld performance 100.000 operations each, time in average after several runs Note: This is very far from a scientific benchmark! The operations executed are simple single-row operations, searching on the PRIMARY KEY INSERT UPDATE SELECT libmysqld mysqld 6.82 s 6.54 s 6.92 s 20.91 s 21.59 s 21.73 s
  25. 25. Libmysqld performance <ul><li>So does this mean that libmysqld is faster than mysqld? </li></ul><ul><ul><li>No, it means that libmysqld has less overhead, that performance is better is a side-effect of that </li></ul></ul><ul><li>So why is this useful data then </li></ul><ul><ul><li>As it means that I need less OS and Hardware resources to achieve the same level of performance! </li></ul></ul>
  26. 26. Resources and contacts <ul><li>Email me at: [email_address] </li></ul><ul><li>Read my blog at: http://karlssonondatabases.blogspot.com/ </li></ul><ul><li>MySQL Forum for Embedded systems: http://forums.mysql.com/list.php?58 </li></ul><ul><li>Contribute to the community with samples and ideas, we need more of those for libmysqld http://forge.mysql.com </li></ul>
  27. 27. Questions? [email_address]
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×