Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if AppArmor causes datadir migration to fail to start or initialization fails

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

I believe many inexperienced people are at a loss about what to do when AppArmor causes datadir migration to fail or initialization fails. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

[problem description]:

Behavior: install a new mysql on a ubuntu machine for local log storage through apt-get

Because the default datadir is under / var/lib/mysql, prepare to reinitialize the datadir:

Mysql_install_db-user=mysql-datadir=/data/mysql_data-basedir=/usr

The error is as follows:

160902 15:25:41 [Note] / usr/sbin/mysqld (mysqld 5.5.50-0ubuntu0.14.04.1) starting as process 25512.

160902 15:25:41 [Warning] Can't create test file / data/mysql_data/10-8-20-62.lower-test

160902 15:25:41 [Warning] Can't create test file / data/mysql_data/10-8-20-62.lower-test

ERROR: 1005 Can't create table 'db' (errno: 13)

160902 15:25:41 [ERROR] Aborting

160902 15:25:41 [Note] / usr/sbin/mysqld: Shutdown complete

Installation of system tables failed! Examine the logs in

/ data/mysql_data for more information.

Add the corresponding permission to / data/mysql_data, execute it again, and report the same error.

So simply migrate the entire folder of / var/lib/mysql to / data/mysql_data, and then start the service:

After cp has passed, modify the datadir location in / etc/mysql/my.cnf, and then mysqld_safe starts, and finds that it cannot be started:

Mysqld_safe mysqld from pid file / data/mysql_data/mysqld.pid ended

Check the error log and find that the plugin.frm file under mysql schema cannot be found when the error is reported:

160902 15:26:51 [Note] Plugin 'FEDERATED' is disabled.

/ usr/sbin/mysqld: Can't find file:'. / mysql/plugin.frm' (errno: 13)

160902 15:26:51 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

After reconfirming the permissions of the directory and files, and then confirming the existence of the files, the startup still fails and the error remains unchanged.

[solution]:

Then I thought that there might be some differences between Ubuntu and CentOS file security policies, and found something like this: (P.S. The company's DB server is all deployed on CentOS, this time in Ubuntu is a special case)

An AppArmor service is installed and exists by default under Ubuntu, which is used for access control.

When installing mysql with apt-get, I guess that access restrictions may have been restricted in the configuration of AppArmor--

As a result, mysqld_safe and mysqld processes cannot read and write files in the newly migrated datadir directory, and mysql_install_db cannot create files under the corresponding mysql schema.

The solution is simple: open this file through an editor and reload AppArmor with the latest configuration:

Vi / etc/apparmor.d/usr.sbin.mysqld

In the usr.sbin.mysqld configuration file, comment out some directories (which have been modified in my.cnf):

Because I modified pid-file, socket, datadir, and log_error in my.cnf, I commented out these directories accordingly:

# / var/log/mysql.log rw

# / var/log/mysql.err rw

# / var/lib/mysql/ r

# / var/lib/mysql/** rwk

# / var/log/mysql/ r

# / var/log/mysql/* rw

# / var/run/mysqld/mysqld.pid rw

# / var/run/mysqld/mysqld.sock w

# / run/mysqld/mysqld.pid rw

Of course, you can simply delete these.

And then add a new datadir directory immediately below it (note that it ends with a comma)

/ data/mysql_data rw

Finally, let AppArmor reload:

# / etc/init.d/apparmor reload

* Reloading AppArmor profiles

Skipping profile in / etc/apparmor.d/disable: usr.sbin.rsyslogd

... done.

Start mysqld again to succeed. (of course, it is also possible to reinitialize mysql_install_db)

P.S. Of course, you can also rudely stop the apparmor service directly.

After reading the above, do you know what to do when AppArmor causes datadir migration to fail to start or initialization fails? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report