1、Can’t change dir to ‘/usr/local/src/mysql/data/’ (Errcode: 13 - Permission denied)

[root@slave1 bin]# ./mysqld --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/src/mysql/ --datadir=/usr/local/src/mysql/data/ --initialize
mysqld: Can't change dir to '/usr/local/src/mysql/data/' (Errcode: 13 - Permission denied)
2022-04-13T03:00:47.645005Z 0 [ERROR] failed to set datadir to /usr/local/src/mysql/data/
2022-04-13T03:00:47.645055Z 0 [ERROR] Aborting

此问题是文件的权限不够,首先根据提示对 /usr/local/src/mysql/data/ 进行赋权,但是没用报了相同的错。后来一想会不会是 mysql 文件没权限,果真,赋权后初始化没报错,但是报了下面的错。

[root@slave1 bin]# chmod -R 777 /usr/local/src/mysql/

返回顶部


2、unknown variable ‘defaults-file=/etc/my.cnf’

[root@slave1 bin]# ./mysqld --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/src/mysql/ --datadir=/usr/local/src/mysql/data/ --initialize
[root@slave1 bin]# cat /usr/local/src/mysql/data/mysql.err 
2022-04-13T03:01:09.305095Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-04-13T03:01:09.395342Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-04-13T03:01:09.648056Z 0 [ERROR] unknown variable 'defaults-file=/etc/my.cnf'
2022-04-13T03:01:09.648079Z 0 [ERROR] Aborting

检查了配置文件,没有问题:

[mysqld]
datadir=/usr/local/src/mysql/data   # data目录                                          
socket=/tmp/mysql.sock              # mysql连接文件目录
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0                    # 符号链接为0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

port=3306                           # 端口号
user=mysql                          # 用户
bind-address=0.0.0.0                # 绑定地址
basedir=/usr/local/src/mysql        # mysql基础目录
character_set_server=utf8mb4        # 字符编码
explicit_defaults_for_timestamp=true  # 时间戳的显式默认值

log-error=/usr/local/src/mysql/data/mysql.err # 日志文件目录
pid-file=/usr/local/src/mysql/data/mysql.pid  # pid文件目录:记录的是当前 mysqld 进程的 pid,pid 亦即 Process ID。

[mysqld_safe]
log-error=/usr/local/src/mysql/data/mysql.err
pid-file=/usr/local/src/mysql/data/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

后来一想,问过大佬初始化的时候那些配置参数位置顺序有没有影响,说的是应该没影响,然后我就改了一下顺序:

cd /usr/local/src/mysql/bin/    # 到mysql/bin目录下
./mysqld --user=mysql
		 --defaults-file=/etc/my.cnf   
         --basedir=/usr/local/src/mysql/ 
         --datadir=/usr/local/src/mysql/data/  
         --initialize                      
cat /usr/local/src/mysql/data/mysql.err #  mysql.err中看初始密码

我尝试这把顺序还原,就是把 --user=mysql 放在最后,成功了:

[root@slave1 mysql]# bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/src/mysql/ --datadir=/usr/local/src/mysql/data/ --user=mysql  --initialize
[root@slave1 mysql]# cat data/mysql.err 
2022-04-13T03:05:32.889428Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-04-13T03:05:32.910841Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-04-13T03:05:32.966470Z 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: 95255e06-bad6-11ec-8094-000c295d6ca9.
2022-04-13T03:05:32.967655Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-04-13T03:05:32.968678Z 1 [Note] A temporary password is generated for root@localhost: ieBlUUcsw0+f

所以,初始化的时候要注意 --user=mysql 要放在最后。

返回顶部


3、ERROR! The server quit without updating PID file

[root@slave2 bin]# service mysql start
Starting MySQL. ERROR! The server quit without updating PID file (/usr/lcoal/src/mysql/data/mysql.pid).

[root@slave2 bin]# service mysql restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL. ERROR! The server quit without updating PID file (/usr/lcoal/src/mysql/data/mysql.pid).

单词拼错:local

返回顶部


Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐