在Linux中,MySQL的basedir通常被设置为/usr或者/usr/local。在这个目录下,大家可以看到MySQL的许多文件和子目录,包括bin(binary,二进制文件)、lib(库文件)、share(共享文件)、man(帮助文件)等等。
通过设置basedir可以让MySQL在正常的运行过程中,快速定位它所需要的文件和子目录,同时也方便管理员对MySQL进行管理。例如,在/usr/share/mysql目录下可以找到MySQL的配置文件my.cnf,通过修改这个文件可以实现MySQL的配置调整。
# Example MySQL config file for large systems. # # This is for a large system with memory = 512M where the system runs mainly # MySQL. # # MySQL programs run on this machine, querying (and updating) the databases # from themselves or from other machines. # Port-specific configurations (MySQL 5.0 included) are in the file # /etc/mysql/conf.d/ # # This file assumes you use mysqlhotcopy, mysql -p or mysqladmin to perform # backups of databases, not a file backup program. # # If you do not know where your mysql.sock file is, you can find it like this: # sudo find / -type s -name "mysql.sock" # or # mysqld --verbose --help | grep '^socket' [client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 # The MySQL server [mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking
需要注意的是,basedir指向的目录应该具有足够的权限,例如,当MySQL向一个文件写入数据时,该文件所在的目录必须要给MySQL用户具有写入权限。管理员在修改MySQL的配置时,应当注意这一点。