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

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

问题描述

是否可以将我的默认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. 停止MySQL使用以下命令:

  1. Stop MySQL using the following command:

sudo /etc/init.d/mysql stop


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

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


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

  • edit the MySQL configuration file with the following command:

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


  • 查找 datadir 的条目,并更改路径(应为)到新的数据目录。

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

    在终端中输入命令: p>

    In the terminal, enter the command:

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


  • 寻找行开始ning with / var / lib / mysql 。在新路径的行中更改 / var / lib / mysql

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

    保存并关闭文件。

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

    Restart the AppArmor profiles with the command:

    sudo /etc/init.d/apparmor reload
    


  • 使用以下命令重新启动MySQL:

  • Restart MySQL with the command:

    sudo /etc/init.d/mysql restart
    


  • 现在登录到MySQL,您可以访问以前使用的相同数据库。

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

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

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