Home Database Mysql Tutorial 数据目录_MySQL

数据目录_MySQL

Jun 01, 2016 pm 01:57 PM
database user

        数据库是一个复杂而又关键的系统,为确保系统安全、高效运行,需熟悉数据库内部的运作机制,掌握各种维护工具,并做好日常的管理工作。下面列举几项主要工作职责:

服务器的关闭和启动;

管理用户帐号;

管理日志文件;

数据库备份恢复;

数据库优化;

确保数据库数据安全;

数据库软件升级。

数据目录
数据目录是用来存放数据表和相关信息的地方,是数据库的核心。在MySQL中的数据目录根据不同平台的有一些差异:

在UNIX/Linux系统上,如果用源码编译安装,数据目录的位置默认是在/usr/local/mysql/var中;

在UNIX/Linux系统上,如果用二进制发行版安装,数据目录的位置默认是在/usr/local/mysql/data中;

在WINDOWS系统上,数据目录的位置默认是在c:/mysql/data中;

   
在服务器启动时,可用--datadir=dir_name来指定数据目录,也可把它写到配置文件中。

我们还可用命令向服务器查询数据目录的位置,数据目录的变量名是datadir,如:

本文由网页教学网(http://www.webjx.com)整理发布!转载请注明出处,谢谢!

% mysqladmin variables如果在一台机器上同时运行多个服务器,则可根据端口的不时来查询每个服务器的数据目录,如:

% mysqladmin --host=127.0.0.1 --port=port_number variables如果--host是localhost,系统则会用一个UNIX套接字去连接数据库服务器,这时要使用--socket选项,所以查询语句变成:

% mysqladmin --host=localhost --socket=/path/to/socket variablesmysql> SHOW VARIABLES LIKE 'datadir';在windows NT平台上可以使用“.”作为一条命名管道连接的主机名,用--socket选项给出命名管道的名字,如:

c:/ mysqladmin --host=. --socket=pipe_name variables配置文件的中[mysqld]段中的datadir=/path/to/datadir设置也可查询到数据目录。

在mysqld程序的帮助信息里也有程序编译时默认的数据目录信息,可用以下命令显示:

% mysqld --help数据目录是存放数据文件的地方,每个数据库对应目录的不同文件。InnoDB数据表由于用表空间来管理数据库,所以就没这种对应关系。但也是保存在数据目录中的,在数据目录除保存数据库文件外,还可能会保存以下几类文件:

服务器的配置文件,my.cnf;

服务器的进程ID(PID)文件;

服务器的日志文件和状态文件,这些文件对管理数据库有重要的价值;

DES密钥文件或服务器的SSL证书与密钥文件。

数据目录中的所有数据库全部由服务器(mysqld)来管理,客户端不直接操作数据。服务器是客户使用数据的唯一通道。

在MySQL中,每个数据库其实就是在数据目录下一个子目录,show databases命令相当于列出数据目录中的目录清单。create database db_name命令会在数据目录下新建一个db_name的目录,以存放数据库的数据文件。所以我们也可下面的shell命令方式来建立一个空数据库:

% cd datadir
% mkdir db_name
% chmod u=rwx,go-rwx db_name
同理,删除数据库drop database db_name也就是删除数据目录中一个名为db_name的目录及目录中的数据表文件。我们也可用shell这进行操作:

% cd datadir
% rm -rf db_name
   
比较shell方式与drop database方式,drop database db_name命令不能删除db_name目录中创建的其它非数据表文件;由于InnoDB是表空间来管理数据表,所以不能用rm或del命令删除InnoDB的数据表。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

PHP connections to different databases: MySQL, PostgreSQL, Oracle and more PHP connections to different databases: MySQL, PostgreSQL, Oracle and more Jun 01, 2024 pm 03:02 PM

PHP database connection guide: MySQL: Install the MySQLi extension and create a connection (servername, username, password, dbname). PostgreSQL: Install the PgSQL extension and create a connection (host, dbname, user, password). Oracle: Install the OracleOCI8 extension and create a connection (servername, username, password). Practical case: Obtain MySQL data, PostgreSQL query, OracleOCI8 update record.

See all articles