How to change MySQL data directory?(如何更改 MySQL 数据目录?)
问题描述
是否可以将我的默认 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 stopCopy the existing data directory (default located in
/var/lib/mysql) using the following command:sudo cp -R -p /var/lib/mysql /newpathedit the MySQL configuration file with the following command:
sudo gedit /etc/mysql/my.cnf # or perhaps /etc/mysql/mysql.conf.d/mysqld.cnfLook 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.mysqldLook for lines beginning with
/var/lib/mysql. Change/var/lib/mysqlin the lines with the new path.Save and close the file.
Restart the AppArmor profiles with the command:
sudo /etc/init.d/apparmor reloadRestart MySQL with the command:
sudo /etc/init.d/mysql restartNow login to MySQL and you can access the same databases you had before.
这篇关于如何更改 MySQL 数据目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改 MySQL 数据目录?
基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
