Location of MySQL Data directory

Source: Internet
Author: User
Tags command line file system connect mysql mysql in variables socket
mysql| Data | Data Catalog Conceptually, most relational database systems are similar: they all consist of a set of databases, each containing a set of tables. However, all systems have their own methods of managing data, and MySQL is no exception.
In the default settings, all data managed by MySQL server MySQL is stored in the MySQL data directory. All the databases and status files that provide information about server operations are also stored there. If you want to perform the administrative responsibilities of MySQL installation, you should be familiar with the layout and use of the data directory.
This chapter includes the following elements:
How to determine the location of the data directory. Need to know hotel bad  learn line у yu Fu di pishihang 谌荨 how the server organizes and provides access to the databases and tables it manages.
Where to find the status file generated by the server and what is contained in the file. Their content provides information about the operation of the server, which is useful if you encounter a problem.
How to change the default layout or organization of a data directory or a single database. This is important for managing the disk resource allocation of the system-for example, by balancing the activity of the disk in the drive, or by relocating the data to the file system by taking advantage of more free space. You can also use this knowledge to plan the layout of the new database.
Even if you do not perform any MySQL management responsibilities, you can gain by reading the contents of this chapter, and it will never affect your idea of how to run the server.

Location of the Data directory

The location of the default database is compiled in the server. If you are installing MySQL in a source distribution package, the typical default location may be/US r/l o c a l/v a r; if MySQL is installed in a binary distribution package, then/US r/l o c a l/mysql/d A; in the rpm file installation, for/V a r/l i b/mysql.
The location of the data directory can be specified explicitly by--datadir =/p a t H/to/dir when the server is started. This option is useful if you want to place the data directory somewhere other than the default location.
As a MySQL administrator, you should know where the data directory is. If you are running multiple servers, you should have the location of all the data directories. However, if you do not know the location of the directory (perhaps you are replacing the previous administrator and he left a bad record), there are several ways to find it:
You can use the mysqladmin variable to get the data directory path name directly from the server. In Unix, the output is similar to the following:

The output indicates the location of the data directory in the server host/US r/l o c a l/v a R.
In Windows, the output is similar to the following:

If you are running multiple servers, they will listen for different TCP/IP port numbers and sockets. You can connect to the ports and sockets that each server listens on by providing the appropriate--port or--socket options:
% mysqladmin--Port=port_num variables
% mysqladmin--Socket=/path/to/socket variables
The mysqladmin command runs on any host that you connect to the server. If you need to connect to a server on a remote host, use the--host = host_name option:
% mysqladmin--host=host_name variables
In Windows, you can purchase a Windows NT server that forces a specified pipe connection by using--pipe, and listens on the pipe using--socket = Pipe_name to specify the name of the pipe.
C:\>mysqladmin--pipe--socket=pipe_name variables
You can use PS to view any command line currently executing the MySQL process. Try the following commands (depending on the PS version supported by your system) and look for these commands that appear in the output--D a T a D i r:
% PS Axww | grep mysqld Bsd-style PS
% Ps-ef | grep mysqld System V-style PS
If the system is running multiple servers (because multiple data directory locations are found at one time), the PS command will be particularly useful. Its disadvantage is that PS must be running on the server's host and will produce useless information unless the--DATADIR option is explicitly specified on the mysqld command line.
If MySQL is installed from the source distribution package, you can check its configuration information to determine the location of the data directory. For example, the location is available at the highest level of makefile. However, be careful: The position is the value of the variable Localstatedir in the makefile, not the DataDir value. Similarly, if the distribution is positioned in an NFS assembly file system and is used to establish MySQL for several hosts, the configuration information reflects the host that recently established the distribution package. It may not display the data directory of the host you are interested in.
If any of the previous methods are unsuccessful, use Find to search for the database files. The following command searches. F R m (description) file, which is part of the MySQL Setup program:
% Find/-name "*.frm"-print
In these examples in this chapter, the author presents the location of the MySQL data directory as data D I R. You can interpret it as the location of the data directory in your own machine.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.