折腾:
期间,尝试在Mac本地中去重新初始化mysql数据库,结果出错:
<code>➜ AliyunRdsMysql mysqld --initialize mysqld: Can't create directory '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/' (Errcode: 17 - File exists) 2018-04-27T02:28:43.628842Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:28:43.639180Z 0 [ERROR] Aborting </code>
搜:
mac mysqld –initialize Can’t create directory Errcode: 17 – File exists
MySQL :: mysqld –initialize (Errcode: 17 – File exists)
MySQL Bugs: #82281: mysqld –initialize reports “Permission denied”, regardless of permissions
去设置文件夹权限给mysql用户?
先去看看文件夹权限
<code>➜ AliyunRdsMysql ll /usr/local/mysql* lrwxr-xr-x 1 root wheel 30B 4 26 11:28 /usr/local/mysql -> mysql-5.7.22-macos10.13-x86_64 /usr/local/mysql-5.7.22-macos10.13-x86_64: total 48 -rw-r--r-- 1 root wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 root wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 root wheel 1.3K 3 4 23:25 bin drwxr-x--- 13 _mysql _mysql 416B 4 27 10:23 data drwxr-xr-x 5 root wheel 160B 3 4 23:24 docs drwxr-xr-x 50 root wheel 1.6K 3 4 23:24 include drwxr-x--- 2 _mysql _mysql 64B 4 26 11:28 keyring drwxr-xr-x 11 root wheel 352B 4 26 11:28 lib drwxr-xr-x 4 root wheel 128B 3 4 23:24 man drwxr-xr-x 39 root wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 root wheel 192B 3 4 23:24 support-files </code>
发现对应文件夹
data
keyring
的权限,和其不同。
所以强制改为一样的:
<code>cd /usr/local/mysql sudo chown root:wheel data/ keyring/ </code>
➜ mysql git:(master) ✗ sudo ls -lha
total 48
drwxr-xr-x 13 root wheel 416B 4 26 11:28 .
drwxr-xr-x 30 root wheel 960B 4 26 11:28 ..
-rw-r–r– 1 root wheel 18K 3 4 21:40 COPYING
-rw-r–r– 1 root wheel 2.4K 3 4 21:40 README
drwxr-xr-x 40 root wheel 1.3K 3 4 23:25 bin
drwxr-x— 13 root wheel 416B 4 27 10:23 data
drwxr-xr-x 5 root wheel 160B 3 4 23:24 docs
drwxr-xr-x 50 root wheel 1.6K 3 4 23:24 include
drwxr-x— 2 root wheel 64B 4 26 11:28 keyring
drwxr-xr-x 11 root wheel 352B 4 26 11:28 lib
drwxr-xr-x 4 root wheel 128B 3 4 23:24 man
drwxr-xr-x 39 root wheel 1.2K 3 4 23:24 share
drwxr-xr-x 6 root wheel 192B 3 4 23:24 support-files
然后再去试试,问题依旧。
mac mysqld –initialize Errcode 17 File exists
database – Errors with MySQL 5.7 installation on Mac OS X El Capitan – Stack Overflow
<code>➜ mysql git:(master) ✗ mysqld --initialize mysqld: Can't create directory '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/' (Errcode: 17 - File exists) 2018-04-27T02:37:59.880961Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:37:59.885751Z 0 [ERROR] Aborting ➜ mysql git:(master) ✗ sudo chown -R mysql /usr/local/mysql-5.7.22-macos10.13-x86_64/data Password: ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/data ls: data: Permission denied ➜ mysql git:(master) ✗ mysqld --initialize mysqld: Can't create directory '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/' (Errcode: 17 - File exists) 2018-04-27T02:45:09.395529Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:45:09.398914Z 0 [ERROR] Aborting ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 root wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 root wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 root wheel 1.3K 3 4 23:25 bin drwxr-x--- 13 _mysql wheel 416B 4 27 10:23 data drwxr-xr-x 5 root wheel 160B 3 4 23:24 docs drwxr-xr-x 50 root wheel 1.6K 3 4 23:24 include drwxr-x--- 2 root wheel 64B 4 26 11:28 keyring drwxr-xr-x 11 root wheel 352B 4 26 11:28 lib drwxr-xr-x 4 root wheel 128B 3 4 23:24 man drwxr-xr-x 39 root wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 root wheel 192B 3 4 23:24 support-files </code>
MySQL Bugs: #79280: mysqld –initialize –defaults-file is ignored if appended
Ubuntu初始化MySQL碰到的坑 – 再见紫罗兰 – 博客园
<code>➜ mysql git:(master) ✗ ll /etc/com.apple.screensharing.agent.launchd ➜ mysql git:(master) ✗ sudo -rf /usr/local/mysql-5.7.22-macos10.13-x86_64/data usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>] usage: sudo -e [-AknS] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ... ➜ mysql git:(master) ✗ sudo rm -rf /usr/local/mysql-5.7.22-macos10.13-x86_64/data ➜ mysql git:(master) ✗ mysqld --initialize mysqld: Can't create directory '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/' (Errcode: 13 - Permission denied) 2018-04-27T02:49:17.752781Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:49:17.756184Z 0 [ERROR] Aborting ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ ls: /usr/local/mysql-5.7.22-macos10.13-x86_64/data/: No such file or directory ➜ mysql git:(master) ✗ mkdir /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ mkdir: /usr/local/mysql-5.7.22-macos10.13-x86_64/data/: Permission denied ➜ mysql git:(master) ✗ sudo mkdir /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 root wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 root wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 root wheel 1.3K 3 4 23:25 bin drwxr-xr-x 2 root wheel 64B 4 27 10:49 data drwxr-xr-x 5 root wheel 160B 3 4 23:24 docs drwxr-xr-x 50 root wheel 1.6K 3 4 23:24 include drwxr-x--- 2 root wheel 64B 4 26 11:28 keyring drwxr-xr-x 11 root wheel 352B 4 26 11:28 lib drwxr-xr-x 4 root wheel 128B 3 4 23:24 man drwxr-xr-x 39 root wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 root wheel 192B 3 4 23:24 support-files ➜ mysql git:(master) ✗ sudo chown -R mysql /usr/local/mysql-5.7.22-macos10.13-x86_64/data ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 root wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 root wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 root wheel 1.3K 3 4 23:25 bin drwxr-xr-x 2 _mysql wheel 64B 4 27 10:49 data drwxr-xr-x 5 root wheel 160B 3 4 23:24 docs drwxr-xr-x 50 root wheel 1.6K 3 4 23:24 include drwxr-x--- 2 root wheel 64B 4 26 11:28 keyring drwxr-xr-x 11 root wheel 352B 4 26 11:28 lib drwxr-xr-x 4 root wheel 128B 3 4 23:24 man drwxr-xr-x 39 root wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 root wheel 192B 3 4 23:24 support-files ➜ mysql git:(master) ✗ mysqld --initialize mysqld: Can't create/write to file '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/is_writable' (Errcode: 13 - Permission denied) 2018-04-27T02:50:18.135455Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:50:18.138903Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting. 2018-04-27T02:50:18.138922Z 0 [ERROR] Aborting ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ ➜ mysql git:(master) ✗ sudo chown -R mysql:mysql /usr/local/mysql-5.7.22-macos10.13-x86_64/ ➜ mysql git:(master) ✗ mysqld --initialize mysqld: Can't create/write to file '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/is_writable' (Errcode: 13 - Permission denied) 2018-04-27T02:51:08.812702Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:51:08.815740Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting. 2018-04-27T02:51:08.815757Z 0 [ERROR] Aborting ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 _mysql _mysql 18K 3 4 21:40 COPYING -rw-r--r-- 1 _mysql _mysql 2.4K 3 4 21:40 README drwxr-xr-x 40 _mysql _mysql 1.3K 3 4 23:25 bin drwxr-xr-x 2 _mysql _mysql 64B 4 27 10:49 data drwxr-xr-x 5 _mysql _mysql 160B 3 4 23:24 docs drwxr-xr-x 50 _mysql _mysql 1.6K 3 4 23:24 include drwxr-x--- 2 _mysql _mysql 64B 4 26 11:28 keyring drwxr-xr-x 11 _mysql _mysql 352B 4 26 11:28 lib drwxr-xr-x 4 _mysql _mysql 128B 3 4 23:24 man drwxr-xr-x 39 _mysql _mysql 1.2K 3 4 23:24 share drwxr-xr-x 6 _mysql _mysql 192B 3 4 23:24 support-files ➜ mysql git:(master) ✗ sudo chown -R crifan:wheel /usr/local/mysql-5.7.22-macos10.13-x86_64/ ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 crifan wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 crifan wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 crifan wheel 1.3K 3 4 23:25 bin drwxr-xr-x 2 crifan wheel 64B 4 27 10:49 data drwxr-xr-x 5 crifan wheel 160B 3 4 23:24 docs drwxr-xr-x 50 crifan wheel 1.6K 3 4 23:24 include drwxr-x--- 2 crifan wheel 64B 4 26 11:28 keyring drwxr-xr-x 11 crifan wheel 352B 4 26 11:28 lib drwxr-xr-x 4 crifan wheel 128B 3 4 23:24 man drwxr-xr-x 39 crifan wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 crifan wheel 192B 3 4 23:24 support-files ➜ mysql git:(master) ✗ sudo chown -R mysql:mysql /usr/local/mysql-5.7.22-macos10.13-x86_64/data ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 crifan wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 crifan wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 crifan wheel 1.3K 3 4 23:25 bin drwxr-xr-x 2 _mysql _mysql 64B 4 27 10:49 data drwxr-xr-x 5 crifan wheel 160B 3 4 23:24 docs drwxr-xr-x 50 crifan wheel 1.6K 3 4 23:24 include drwxr-x--- 2 crifan wheel 64B 4 26 11:28 keyring drwxr-xr-x 11 crifan wheel 352B 4 26 11:28 lib drwxr-xr-x 4 crifan wheel 128B 3 4 23:24 man drwxr-xr-x 39 crifan wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 crifan wheel 192B 3 4 23:24 support-files ➜ mysql git:(master) ✗ sudo chown -R mysql:mysql /usr/local/mysql-5.7.22-macos10.13-x86_64/keyring ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 crifan wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 crifan wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 crifan wheel 1.3K 3 4 23:25 bin drwxr-xr-x 2 _mysql _mysql 64B 4 27 10:49 data drwxr-xr-x 5 crifan wheel 160B 3 4 23:24 docs drwxr-xr-x 50 crifan wheel 1.6K 3 4 23:24 include drwxr-x--- 2 _mysql _mysql 64B 4 26 11:28 keyring drwxr-xr-x 11 crifan wheel 352B 4 26 11:28 lib drwxr-xr-x 4 crifan wheel 128B 3 4 23:24 man drwxr-xr-x 39 crifan wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 crifan wheel 192B 3 4 23:24 support-files ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/data ➜ mysql git:(master) ✗ mysqld --initialize mysqld: Can't create/write to file '/usr/local/mysql-5.7.22-macos10.13-x86_64/data/is_writable' (Errcode: 13 - Permission denied) 2018-04-27T02:53:18.478871Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:53:18.485012Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting. 2018-04-27T02:53:18.485095Z 0 [ERROR] Aborting </code>
mysqld: Can’t create/write to file data/is_writable (Errcode: 13 – Permission denied)
mac mysqld Can’t create/write to file data/is_writable (Errcode: 13 – Permission denied)
mysql container immediately exited (1) · Issue #237 · laradock/laradock
Docker – 编写永久数据MySQL – IT屋-程序员软件开发技术分享社区
mac mysqld Can’t create/write to file data/is_writable Errcode 13 Permission denied
算了,去弄777拉倒:
<code>➜ mysql git:(master) ✗ sudo chmod 777 /usr/local/mysql-5.7.22-macos10.13-x86_64/data Password: ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/data ➜ mysql git:(master) ✗ ll /usr/local/mysql-5.7.22-macos10.13-x86_64/ total 48 -rw-r--r-- 1 crifan wheel 18K 3 4 21:40 COPYING -rw-r--r-- 1 crifan wheel 2.4K 3 4 21:40 README drwxr-xr-x 40 crifan wheel 1.3K 3 4 23:25 bin drwxrwxrwx 2 _mysql _mysql 64B 4 27 10:49 data drwxr-xr-x 5 crifan wheel 160B 3 4 23:24 docs drwxr-xr-x 50 crifan wheel 1.6K 3 4 23:24 include drwxr-x--- 2 _mysql _mysql 64B 4 26 11:28 keyring drwxr-xr-x 11 crifan wheel 352B 4 26 11:28 lib drwxr-xr-x 4 crifan wheel 128B 3 4 23:24 man drwxr-xr-x 39 crifan wheel 1.2K 3 4 23:24 share drwxr-xr-x 6 crifan wheel 192B 3 4 23:24 support-files </code>
然后就可以了:
<code>➜ mysql git:(master) ✗ mysqld --initialize 2018-04-27T02:59:51.470525Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-04-27T02:59:51.474513Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ is case insensitive 2018-04-27T02:59:51.722216Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-04-27T02:59:51.758490Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-04-27T02:59:51.769637Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0e0a9c82-49c7-11e8-9518-641b5a7436b1. 2018-04-27T02:59:51.795506Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-04-27T02:59:51.801157Z 1 [Note] A temporary password is generated for root@localhost: sK.2kMuqsw02 </code>
【总结】
此处就是权限问题。
最终是:
把出了问题的文件夹,给了777的权限:
<code>sudo chmod 777 /usr/local/mysql-5.7.22-macos10.13-x86_64/data </code>
后,就可以正常执行:
<code>mysqld --initialize </code>
去重新初始化数据库了。
转载请注明:在路上 » 【已解决】Mac中mysqld去重新初始化mysql出错:mysqld Can’t create directory /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ Errcode 17 File exists