如何更改 MySQL 数据目录? [英] How to change MySQL data directory?

查看:31
本文介绍了如何更改 MySQL 数据目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将我的默认 MySQL 数据目录更改为其他路径?我可以从旧位置访问数据库吗?

解决方案

  1. 使用以下命令停止 MySQL:

    sudo/etc/init.d/mysql stop

  2. 使用以下命令复制现有数据目录(默认位于/var/lib/mysql):

    sudo cp -R -p/var/lib/mysql/newpath

  3. 使用以下命令编辑 MySQL 配置文件:

    sudo gedit/etc/mysql/my.cnf # 或者/etc/mysql/mysql.conf.d/mysqld.cnf

  4. 查找datadir 的条目,并将路径(应该是/var/lib/mysql)更改为新的数据目录.p>

  5. 在终端输入命令:

    sudo gedit/etc/apparmor.d/usr.sbin.mysqld

  6. 查找以 /var/lib/mysql 开头的行.使用新路径在行中更改 /var/lib/mysql.

  7. 保存并关闭文件.

  8. 使用以下命令重新启动 AppArmor 配置文件:

    sudo/etc/init.d/apparmor reload

  9. 使用以下命令重启 MySQL:

    sudo/etc/init.d/mysql restart

  10. 现在登录 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?

解决方案

  1. Stop MySQL using the following command:

    sudo /etc/init.d/mysql stop
    

  2. Copy the existing data directory (default located in /var/lib/mysql) using the following command:

    sudo cp -R -p /var/lib/mysql /newpath
    

  3. edit the MySQL configuration file with the following command:

    sudo gedit /etc/mysql/my.cnf   # or perhaps /etc/mysql/mysql.conf.d/mysqld.cnf
    

  4. Look for the entry for datadir, and change the path (which should be /var/lib/mysql) to the new data directory.

  5. In the terminal, enter the command:

    sudo gedit /etc/apparmor.d/usr.sbin.mysqld
    

  6. Look for lines beginning with /var/lib/mysql. Change /var/lib/mysql in the lines with the new path.

  7. Save and close the file.

  8. Restart the AppArmor profiles with the command:

    sudo /etc/init.d/apparmor reload
    

  9. Restart MySQL with the command:

    sudo /etc/init.d/mysql restart
    

  10. Now login to MySQL and you can access the same databases you had before.

这篇关于如何更改 MySQL 数据目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆