简体   繁体   English

mysql数据目录位置

[英]mysql data directory location

I installed mysql in Mac after downloding its dmg file version 64 bit.下载 64 位 dmg 文件版本后,我在 Mac 中安装了 mysql。 While trying to create a database it gave me error 1006 -- can't create database.在尝试创建数据库时,它给了我错误 1006 -- 无法创建数据库。 After browsing a number of website, it seems due to user ownership setting of mysql "data directory" location that needs to be changed.浏览了多个网站后,似乎是由于mysql“数据目录”位置的用户所有权设置需要更改。

Where is mysql default "data directory"? mysql默认的“数据目录”在哪里? I could not find /var/lib/mysql in localhost.我在本地主机中找不到 /var/lib/mysql。

THANKS.谢谢。

如果该软件是 Sequel pro,则 Mac OSX 上的默认安装 mysql 的数据位于此处:

/usr/local/var/mysql

See if you have a file located under /etc/my.cnf .查看/etc/my.cnf下是否有文件。 If so, it should tell you where the data directory is.如果是这样,它应该告诉您数据目录在哪里。

For example:例如:

[mysqld]
set-variable=local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
...

My guess is that your mysql might be installed to /usr/local/mysql-XXX.我的猜测是您的 mysql 可能安装到 /usr/local/mysql-XXX。

You may find these MySQL reference manual links useful:您可能会发现这些 MySQL 参考手册链接很有用:

As suggested, I edited this message to place a proper answer.按照建议,我编辑了这条消息以给出正确的答案。

The 'physical' location of the mysql databases are under /usr/local/mysql mysql 数据库的“物理”位置在 /usr/local/mysql 下

the mysql is a symlink to the current active mysql installation, in my case the exact folder is mysql-5.6.10-osx10.7-x86_64. mysql 是当前活动 mysql 安装的符号链接,在我的情况下,确切的文件夹是 mysql-5.6.10-osx10.7-x86_64。

Inside that folder you'll see another data folder, inside it are RESTRICTED folders with your databases.在该文件夹中,您将看到另一个数据文件夹,其中包含您的数据库的 RESTRICTED 文件夹。

You can't actually see the size of your databases (that was my issue) from the Finder because the folder are protected, you can though see from the terminal with sudo du -sh /usr/local/mysql/data/{your-database-name} and like this you'll get a nice formatted output with the size.您实际上无法从 Finder 中看到数据库的大小(这是我的问题),因为该文件夹受到保护,但您可以使用sudo du -sh /usr/local/mysql/data/{your-database-name}像这样你会得到一个很好的格式化输出。

In those folder you have different files with all the folders present in your database, so it's safer to check the db's folder to get a size.在这些文件夹中,您有不同的文件,其中包含数据库中存在的所有文件夹,因此检查 db 的文件夹以获取大小更安全。

That's it.而已。 Enjoy!享受!

Well, if yo don't know where is my.cnf (such Mac OS X installed with homebrew), or You are looking found others choices:好吧,如果您不知道 my.cnf 在哪里(例如安装了自制软件的 Mac OS X),或者您正在寻找其他选择:

ps aux|grep mysql
abkrim            1160   0.0  0.2  2913068  26224   ??  R    Tue04PM   0:14.63 /usr/local/opt/mariadb/bin/mysqld --basedir=/usr/local/opt/mariadb --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mariadb/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/iMac-2.local.err --pid-file=iMac-2.local.pid

You get datadir=/usr/local/var/mysql你得到datadir=/usr/local/var/mysql

检查mysql的根文件夹在哪里:

mysql_config

If you are using macOS {mine 'High Sierra'} and Installed XAMPP如果您使用的是macOS {mine 'High Sierra'}并安装了 XAMPP

You can find mysql data files;可以找到mysql数据文件;

Go to : /Applications/XAMPP/xamppfiles/var/mysql/转到: /Applications/XAMPP/xamppfiles/var/mysql/

If you install MySQL via homebrew on MacOS, you might need to delete your old data directory /usr/local/var/mysql .如果您在 MacOS 上通过自制软件安装 MySQL,您可能需要删除旧数据目录/usr/local/var/mysql Otherwise, it will fail during the initialization process with the following error:否则,它会在初始化过程中失败并出现以下错误:

==> /usr/local/Cellar/mysql/8.0.16/bin/mysqld --initialize-insecure --user=hohoho --basedir=/usr/local/Cellar/mysql/8.0.16 --datadir=/usr/local/var/mysql --tmpdir=/tmp
2019-07-17T16:30:51.828887Z 0 [System] [MY-013169] [Server] /usr/local/Cellar/mysql/8.0.16/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 93487
2019-07-17T16:30:51.830375Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2019-07-17T16:30:51.830381Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /usr/local/var/mysql/ is unusable. You can safely remove it.
2019-07-17T16:30:51.830410Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-07-17T16:30:51.830540Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.16/bin/mysqld: Shutdown complete (mysqld 8.0.16)  Homebrew.

If you are using Homebrew to install MySQL@5.7, the location is如果你使用 Homebrew 安装 MySQL@5.7,位置是

/usr/local/Homebrew/var/mysql

I don't know if the location is the same for other versions.我不知道其他版本的位置是否相同。

On M1 and homebrew the "data directory" is:在 M1 和自制软件上,“数据目录”是:

/opt/homebrew/var/mysql

And the main path is:主要路径是:

/opt/homebrew/Cellar/mysql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM