diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index c9f98a701ef183744d516a5f7e562a2fadf30714..d4cb916a89cb012f2d684825423239f3389f95ba 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -435,11 +435,6 @@ void STDCALL mysql_server_end()
   my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR));
   copy_arguments_ptr=0;
   clean_up(0);
-#ifdef THREAD
-  /* Don't call my_thread_end() if the application is using MY_INIT() */
-  if (!org_my_init_done)
-    my_thread_end();
-#endif
   /* If library called my_init(), free memory allocated by it */
   if (!org_my_init_done)
     my_end(0);
diff --git a/sql/derror.cc b/sql/derror.cc
index 78efdcc33f31fe9055bd8cf74af19b178fd6e515..7f4068c487e0ac6693af89c40f71fcf97f781a56 100644
--- a/sql/derror.cc
+++ b/sql/derror.cc
@@ -20,27 +20,28 @@
 #include "mysql_priv.h"
 #include "mysys_err.h"
 
-static void read_texts(const char *file_name,const char ***point,
+static bool read_texts(const char *file_name,const char ***point,
 		       uint error_messages);
 static void init_myfunc_errs(void);
 
 	/* Read messages from errorfile */
 
-void init_errmessage(void)
+bool init_errmessage(void)
 {
   DBUG_ENTER("init_errmessage");
 
-  read_texts(ERRMSG_FILE,&my_errmsg[ERRMAPP],ER_ERROR_MESSAGES);
+  if (read_texts(ERRMSG_FILE,&my_errmsg[ERRMAPP],ER_ERROR_MESSAGES))
+    DBUG_RETURN(TRUE);
   errmesg=my_errmsg[ERRMAPP];		/* Init global variabel */
   init_myfunc_errs();			/* Init myfunc messages */
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(FALSE);
 }
 
 
 	/* Read text from packed textfile in language-directory */
 	/* If we can't read messagefile then it's panic- we can't continue */
 
-static void read_texts(const char *file_name,const char ***point,
+static bool read_texts(const char *file_name,const char ***point,
 		       uint error_messages)
 {
   register uint i;
@@ -116,7 +117,7 @@ Check that the above file is the right version for this program!",
     point[i]= *point +uint2korr(head+10+i+i);
   }
   VOID(my_close(file,MYF(0)));
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(FALSE);
 
 err:
   switch (funktpos) {
diff --git a/sql/init.cc b/sql/init.cc
index 50d504068a03642130e87519440c48cb89404ae1..8b15fef4ee3f0b2bf2c6e6c071a0438fa5f8cdd1 100644
--- a/sql/init.cc
+++ b/sql/init.cc
@@ -37,7 +37,9 @@ void unireg_init(ulong options)
 #ifdef USE_MY_ATOF
   init_my_atof();			/* use our atof */
 #endif
+#ifndef EMBEDDED_LIBRARY
   my_abort_hook=unireg_abort;		/* Abort with close of databases */
+#endif
 
   VOID(strmov(reg_ext,".frm"));
   for (i=0 ; i < 6 ; i++)		// YYMMDDHHMMSS
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index c8d793ede29556301fadaf041c8bc6857a644a0f..83cd303b438c2ea9b9512b4a3cc4ba7a42704188 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -725,7 +725,7 @@ void key_restore(TABLE *form,byte *key,uint index,uint key_length);
 int key_cmp(TABLE *form,const byte *key,uint index,uint key_length);
 void key_unpack(String *to,TABLE *form,uint index);
 bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields);
-void init_errmessage(void);
+bool init_errmessage(void);
 
 void sql_perror(const char *message);
 void sql_print_error(const char *format,...)
@@ -937,7 +937,11 @@ extern String *make_datetime(String *str, TIME *l_time,
 
 int test_if_number(char *str,int *res,bool allow_wildcards);
 void change_byte(byte *,uint,char,char);
+#ifndef EMBEDDED_LIBRARY
 extern "C" void unireg_abort(int exit_code);
+#else
+#define unireg_abort(exit_code) DBUG_RETURN(exit_code)
+#endif
 void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
 		      SQL_SELECT *select,
 		      int use_record_cache, bool print_errors);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 8a8c3a6c32d696f7b6475be11e2f92aef48fa2af..da7d3df02512b35515557ffecc7ffcfe3ba88aa7 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -851,6 +851,7 @@ extern "C" sig_handler print_signal_warning(int sig)
     (Mac OS X) we have to call exit() instead if pthread_exit().
 */
 
+#ifndef EMBEDDED_LIBRARY
 void unireg_end(void)
 {
   clean_up(1);
@@ -862,7 +863,6 @@ void unireg_end(void)
 #endif
 }
 
-
 extern "C" void unireg_abort(int exit_code)
 {
   DBUG_ENTER("unireg_abort");
@@ -874,7 +874,7 @@ extern "C" void unireg_abort(int exit_code)
   my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
   exit(exit_code); /* purecov: inspected */
 }
-
+#endif
 
 void clean_up(bool print_message)
 {
@@ -1024,6 +1024,7 @@ static void set_ports()
   }
 }
 
+#ifndef EMBEDDED_LIBRARY
 /* Change to run as another user if started with --user */
 
 static void set_user(const char *user)
@@ -1106,7 +1107,6 @@ static void set_root(const char *path)
 #endif
 }
 
-
 static void server_init(void)
 {
   struct sockaddr_in	IPaddr;
@@ -1257,6 +1257,7 @@ static void server_init(void)
   DBUG_VOID_RETURN;
 }
 
+#endif /*!EMBEDDED_LIBRARY*/
 
 void yyerror(const char *s)
 {
@@ -2120,7 +2121,8 @@ static int init_common_variables(const char *conf_file_name, int argc,
   open_files_limit= 0;		/* Can't set or detect limit */
 #endif
   unireg_init(opt_specialflag); /* Set up extern variabels */
-  init_errmessage();		/* Read error messages from file */
+  if (init_errmessage())	/* Read error messages from file */
+    return 1;
   init_client_errs();
   lex_init();
   item_init();
@@ -2233,6 +2235,7 @@ static void init_ssl()
 
 static int init_server_components()
 {
+  DBUG_ENTER("init_server_components");
   table_cache_init();
   hostname_cache_init();
   query_cache_result_size_limit(query_cache_limit);
@@ -2324,7 +2327,7 @@ Now disabling --log-slave-updates.");
 
   init_max_user_conn();
   init_update_queries();
-  return 0;
+  DBUG_RETURN(0);
 }
 
 
@@ -5604,8 +5607,10 @@ static void get_options(int argc,char **argv)
   /* Set global MyISAM variables from delay_key_write_options */
   fix_delay_key_write((THD*) 0, OPT_GLOBAL);
 
+#ifndef EMBEDDED_LIBRARY
   if (mysqld_chroot)
     set_root(mysqld_chroot);
+#endif
   fix_paths();
 
   /*