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 数据目录?
- 导入具有可变标题的 Excel 文件 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
