12.3.1. Ubuntu安装MySQL

sudo apt install mysql-server
sudo apt stop mysql
mkdir -p /mnt/datadisk0/mysql
sudo cp -rf /var/lib/mysql /mnt/datadisk0/mysql/data
sudo chown -R mysql:msql /mnt/datadisk0/mysql
sudo vi /etc/mysql/mysql.conf.d/mysqld.conf
datadir = /mnt/datadisk0/mysql/data

修改apparmor的配置,允许对mysql的数据目录进行读写:

sudo vi /etc/apparmor.d/usr.sbin.mysqld
# Allow data dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
/mnt/datadisk0/mysql/data/ r,
/mnt/datadisk0/mysql/data/** rwk,
sudo systemctl restart apparmor
sudo systemctl start mysql
sudo mysql -u root