如何更改 MySQL 数据目录?

How to change MySQL data directory?(如何更改 MySQL 数据目录?)
本文介绍了如何更改 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 数据目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)