Ubuntu-16.04 changing MySQL default data storage directory

Time:2021-11-25

Log in to MYSQL to view the current data storage directory

mysql -uroot -p

mysql> select @@datadir;
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+
1 row in set (0.00 sec)

Close MySQL server

sudo systemctl stop mysql

Confirm that MySQL server is closed

sudo systemctl status mysql
  • Close without error, and the output is similar to “Jul 18 11:24:20 ubuntu-512mb-nyc1-01 SYSTEMd [1]: stopped MySQL community server.”

Transfer data directory

sudo rsync -av /var/lib/mysql /data/

Backup source data

sudo mv /var/lib/mysql /var/lib/mysql.bak
sudo mkdir /var/lib/mysql/mysql -p
  • Sudo MKDIR / var / lib / MySQL / MySQL – P is used to verify that the directory is correct in / usr / share / MySQL / mysql-systemd-start

Modify MySQL server configuration / etc / MySQL / mysql.conf.d/mysqld.cnf

datadir=/data/mysql

Modify the AppArmor permission and add the following content to / etc / apparmor.d/tunables/alias

alias /var/lib/mysql/ -> /data/mysql/,

Restart AppArmor

sudo systemctl restart apparmor
  • No alias content is added, which may cause

<pre>
Job for mysql.service failed because the control process exited with error code. See “systemctl status mysql.service”
and “journalctl -xe” for details.
</pre>

Start MySQL server

sudo systemctl start mysql
sudo systemctl status mysql

Original link
https://www.digitalocean.com/…

Welcome to join our exclusive QQ discussion group ① 233415606 ② 233415756

Recommended Today

Apache sqoop

Source: dark horse big data 1.png From the standpoint of Apache, data flow can be divided into data import and export: Import: data import. RDBMS—–>Hadoop Export: data export. Hadoop—->RDBMS 1.2 sqoop installation The prerequisite for installing sqoop is that you already have a Java and Hadoop environment. Latest stable version: 1.4.6 Download the sqoop installation […]