When you are linking an application program to use the MySQL
client library, you might get undefined reference errors for
symbols that start with mysql_
, such as those
shown here:
/tmp/ccFKsdPa.o: In function `main': /tmp/ccFKsdPa.o(.text+0xb): undefined reference to `mysql_init' /tmp/ccFKsdPa.o(.text+0x31): undefined reference to `mysql_real_connect' /tmp/ccFKsdPa.o(.text+0x57): undefined reference to `mysql_real_connect' /tmp/ccFKsdPa.o(.text+0x69): undefined reference to `mysql_error' /tmp/ccFKsdPa.o(.text+0x9a): undefined reference to `mysql_close'
You should be able to solve this problem by adding
-Ldir_path -lmysqlclient
at the end of your
link command, where dir_path
represents the
pathname of the directory where the client library is located.
To determine the correct directory, try this command:
shell> mysql_config --libs
The output from mysql_config might indicate other libraries that should be specified on the link command as well.
If you get undefined reference
errors for the
uncompress
or compress
function, add -lz
to the end of your link
command and try again.
If you get undefined reference
errors for a
function that should exist on your system, such as
connect
, check the manual page for the
function in question to determine which libraries you should add
to the link command.
You might get undefined reference
errors such
as the following for functions that don't exist on your system:
mf_format.o(.text+0x201): undefined reference to `__lxstat'
This usually means that your MySQL client library was compiled on a system that is not 100% compatible with yours. In this case, you should download the latest MySQL source distribution and compile MySQL yourself. See Sección 2.8, “Instalación de MySQL usando una distribución de código fuente”.
You might get undefined reference errors at runtime when you try
to execute a MySQL program. If these errors specify symbols that
start with mysql_
or indicate that the
mysqlclient
library can't be found, it means
that your system can't find the shared
libmysqlclient.so
library. The fix for this
is to tell your system to search for shared libraries where the
library is located. Use whichever of the following methods is
appropriate for your system:
-
Add the path to the directory where
libmysqlclient.so
is located to theLD_LIBRARY_PATH
environment variable. -
Add the path to the directory where
libmysqlclient.so
is located to theLD_LIBRARY
environment variable. -
Copy
libmysqlclient.so
to some directory that is searched by your system, such as/lib
, and update the shared library information by executingldconfig
.
Another way to solve this problem is by linking your program
statically with the -static
option, or by
removing the dynamic MySQL libraries before linking your code.
Before trying the second method, you should be sure that no
other programs are using the dynamic libraries.
On Windows, you can run the server as a Windows service using normal user accounts beginning with MySQL 4.0.17 and 4.1.2. (Older MySQL versions required you to have administrator rights. This was a bug introduced in MySQL 3.23.54.)
On Unix, the MySQL server mysqld can be
started and run by any user. However, you should avoid running
the server as the Unix root
user for security
reasons. In order to change mysqld to run as
a normal unprivileged Unix user
user_name
, you must do the following:
-
Stop the server if it's running (use mysqladmin shutdown).
-
Change the database directories and files so that
user_name
has privileges to read and write files in them (you might need to do this as the Unixroot
user):shell> chown -R
user_name
/path/to/mysql/datadir
If you do not do this, the server is not able to access databases or tables when it runs as
user_name
.If directories or files within the MySQL data directory are symbolic links, you'll also need to follow those links and change the directories and files they point to.
chown -R
might not follow symbolic links for you. -
Start the server as user
user_name
. If you are using MySQL 3.22 or later, another alternative is to start mysqld as the Unixroot
user and use the--user=
user_name
option. mysqld starts up, then switches to run as the Unix useruser_name
before accepting any connections. -
To start the server as the given user automatically at system startup time, specify the username by adding a
user
option to the[mysqld]
group of the/etc/my.cnf
option file or themy.cnf
option file in the server's data directory. For example:[mysqld] user=
user_name
If your Unix machine itself isn't secured, you should assign
passwords to the MySQL root
accounts in the
grant tables. Otherwise, any user with a login account on that
machine can run the mysql client with a
--user=root
option and perform any operation.
(It is a good idea to assign passwords to MySQL accounts in any
case, but especially so when other login accounts exist on the
server host.) See Sección 2.9, “Puesta en marcha y comprobación después de la instalación”.
If you have problems with file permissions, the
UMASK
environment variable might be set
incorrectly when mysqld starts. For example,
MySQL might issue the following error message when you create a
table:
ERROR: Can't find file: 'path/with/filename.frm' (Errcode: 13)
The default UMASK
value is
0660
. You can change this behavior by
starting mysqld_safe as follows:
shell> UMASK=384 # = 600 in octal shell> export UMASK shell> mysqld_safe &
By default, MySQL creates database and RAID
directories with an access permission value of
0700
. You can modify this behavior by setting
the UMASK_DIR
variable. If you set its value,
new directories are created with the combined
UMASK
and UMASK_DIR
values. For example, if you want to give group access to all new
directories, you can do this:
shell> UMASK_DIR=504 # = 770 in octal shell> export UMASK_DIR shell> mysqld_safe &
In MySQL 3.23.25 and above, MySQL assumes that the value for
UMASK
and UMASK_DIR
is in
octal if it starts with a zero.