问题描述
是否可以将我的默认 MySQL 数据目录更改为其他路径?我可以从旧位置访问数据库吗?
使用以下命令停止 MySQL:
sudo/etc/init.d/mysql stop
使用以下命令复制现有数据目录(默认位于
/var/lib/mysql
):sudo cp -R -p/var/lib/mysql/newpath
使用以下命令编辑 MySQL 配置文件:
sudo gedit/etc/mysql/my.cnf # 或者/etc/mysql/mysql.conf.d/mysqld.cnf
查找
datadir
的条目,并将路径(应该是/var/lib/mysql
)更改为新的数据目录.p>在终端输入命令:
sudo gedit/etc/apparmor.d/usr.sbin.mysqld
查找以
/var/lib/mysql
开头的行.使用新路径在行中更改/var/lib/mysql
.保存并关闭文件.
使用以下命令重新启动 AppArmor 配置文件:
sudo/etc/init.d/apparmor reload
使用以下命令重启 MySQL:
sudo/etc/init.d/mysql restart
现在登录 MySQL,您可以访问与以前相同的数据库.
Is it possible to change my default MySQL data directory to another path? Will I be able to access the databases from the old location?
Stop MySQL using the following command:
sudo /etc/init.d/mysql stop
Copy the existing data directory (default located in
/var/lib/mysql
) using the following command:sudo cp -R -p /var/lib/mysql /newpath
edit the MySQL configuration file with the following command:
sudo gedit /etc/mysql/my.cnf # or perhaps /etc/mysql/mysql.conf.d/mysqld.cnf
Look for the entry for
datadir
, and change the path (which should be/var/lib/mysql
) to the new data directory.In the terminal, enter the command:
sudo gedit /etc/apparmor.d/usr.sbin.mysqld
Look for lines beginning with
/var/lib/mysql
. Change/var/lib/mysql
in the lines with the new path.Save and close the file.
Restart the AppArmor profiles with the command:
sudo /etc/init.d/apparmor reload
Restart MySQL with the command:
sudo /etc/init.d/mysql restart
Now login to MySQL and you can access the same databases you had before.
这篇关于如何更改 MySQL 数据目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!