MySQL 5.7在Ubuntu 18.04上重新初始化mysqld –initialize mysqld: Can’t create directory (Errcode: 13 – Permission denied)

注意在ubuntu上mysqld –initialize ,要配置apparmor,可以通过修改参数文件 vim /etc/apparmor.d/usr.sbin.mysqld, 也可以像我一样直接禁用mysql的apparmor profile。

否则会出现 Can’t create directory (Errcode: 13 – Permission denied) 错误

 

su -  root


systemctl stop mysql

 
mkdir -p /d01/mysql 


#这里重新初始化的目标目录是/d01/mysql


chown mysql:mysql /d01
chown mysql:mysql /d01/mysql 


#一些权限设置
mkdir /var/run/mysqld
chown mysql:mysql /var/run/mysqld
chown mysql:mysql /var/log/mysql
chown mysql:mysql /var/log/mysql/*

修改 /etc/mysql/mysql.conf.d/mysqld.cnf

 
datadir         = /d01/mysql


下面 禁用mysql的apparmor profile

aa-status |grep mysql
ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld



重启 apparmor

 systemctl restart apparmor

aa-status |grep mysql

//aa-status |grep mysql 应当无结果



mysqld --initialize --user=mysql




root@vultr:~# grep password  /var/log/mysql/error.log 
2020-04-27T07:39:28.126296Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-04-27T07:39:32.229124Z 0 [Note] Shutting down plugin 'sha256_password'
2020-04-27T07:39:32.229128Z 0 [Note] Shutting down plugin 'mysql_native_password'
2020-04-27T07:39:44.435551Z 0 [Note] Shutting down plugin 'sha256_password'
2020-04-27T07:39:44.435556Z 0 [Note] Shutting down plugin 'mysql_native_password'
2020-04-27T07:41:01.360902Z 1 [Note] A temporary password is generated for root@localhost: T#jTiKh+d9Og


临时密码T#jTiKh+d9Og

systemctl start mysql 

mysql -uroot -pT#jTiKh+d9Og
 



Comment

*

沪ICP备14014813号

沪公网安备 31010802001379号