`
ggsonic
  • 浏览: 266698 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

mysql change data dir

 
阅读更多
[ubuntu]
MySQL is a widely used and fast SQL database server. It is a client/server implementation that consists of a server daemon (mysqld) and many different client programs/libraries.

If you want to install Mysql database server in Ubuntu check this tutorial.
What is Mysql Data Directory?

Mysql data directory is important part where all the mysql databases storage location.By default MySQL data default directory located in /var/lib/mysql.If you are running out of space in /var partition you need to move this to some other location.

Note:- This is only for advanced users and before moving default directory make a backup of your mysal databases.

Procedure to follow

Open the terminal

First you need to Stop MySQL using the following command

sudo /etc/init.d/mysql stop

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

sudo cp -R -p /var/lib/mysql /path/to/new/datadir

All you need are the data files, so delete the others with the command

sudo rm /path/to/new/datadir

Note:- You will get a message about not being able to delete some directories, but that's what you want.

Now edit the MySQL configuration file with the following command

gksu gedit /etc/mysql/my.cnf

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

Important Note:-From Ubuntu 7.10 (Gutsy Gibbon) forward, Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you'll never be able to restart MySQL with the new datadir location.

In the terminal, enter the command

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

Copy the lines beginning with "/var/lib/mysql", comment out the originals with hash marks ("#"), and paste the lines below the originals.

Now change "/var/lib/mysql" in the two new lines with "/path/to/new/datadir". Save and close the file.

Restart the AppArmor profiles with the command

sudo /etc/init.d/apparmor reload

( sudo vim /etc/init/mysql.conf change /var/lib/mysql to your new path)

Restart MySQL with the command

sudo /etc/init.d/mysql restart
or
sudo start mysql

(if fails, try  sudo chown -R mysql:mysql /path/to/new/datadir)
Now MySQL should start with no errors, and your data will be stored in the new data directory location.
分享到:
评论

相关推荐

    MYSQL权限不够解决办法

    ### MySQL权限不够解决办法 在使用MySQL数据库的过程中,可能会遇到“权限不足”的错误提示,这通常是因为当前用户没有足够的权限来执行某些操作(如创建表、删除数据等)。本文将详细介绍如何解决MySQL权限不足的...

    mysql5.7 arm64 deb安装包

    MySQL 5.7是MySQL数据库管理系统的一个重要版本,特别针对arm64架构进行了优化,使其能够在基于ARM架构的系统上高效运行,例如树莓派(Raspberry Pi)。树莓派是一款小巧、低成本的单板计算机,广泛应用于教育、DIY...

    mysql5.5 rpm包方式安装 - 手册

    /usr/sbin/mysqld: Can't change dir to '/data/mysql/' (Errcode: 13) ``` 那么可能是 SELinux 问题,可以通过修改 /etc/selinux/config 文件来解决,例如,将 selinux 设置为 disabled 或者 permissive。 八、...

    MySQL5.7 免安装版配置

    * can't change dir to ' ' 解决方法:请参考 MySQL5.7 正确的安装步骤。 * Navicat 工具登录 MySQL 报错,错误代码为 1862,但通过命令行可进入 MySQL 解决方法:(1) 通过命令行,以 root 权限登录 MySQL (2) 通过 ...

    Mysql+Maxscale2.0读写分离

    CHANGE MASTER TO MASTER_HOST='master_ip', MASTER_USER='replication_user', MASTER_PASSWORD='replication_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107; ``` 然后启动从服务器上的...

    mysql-5.7.17-winx64的安装、配置和初始化

    - **错误提示**:“Can't change dir to 'F:\mysql\data\' (Errcode:2 - No such file or directory)” - 解决方案:确保`datadir`配置正确指向已存在的数据目录。 - **警告信息**:“TIMESTAMP with implicit ...

    MYSQL5.7.24安装没有data目录和my-default.ini及服务无法启动的完美解决办法

    1.Can’t change dir to ‘D:\from20181022\soft\mysql-5.7.24\mysql-5.7.24-winx64\data'(Errcode : 2 – No such file or directory) 2.MySQL 服务正在启动 ,MySQL 服务无法启动。 经过尝试整合,最终安装...

    MySQL运维-应急处理手册

    chown mysql:mysql /mysqldata/mysql_3306/dbdata/* chown mysql:mysql /mysqldata/mysql_3306/log/* service mysqld start ``` 3. **建立复制关系并启动复制**: - 登录从库。 ```sql mysql -uxxx -pxxx ``...

    Mysql MHA详细配置手册

    文档中推荐使用mysqldump工具配合master-data参数进行数据备份,并使用mysql命令导入备份文件来设置主从复制环境。 - 备份主服务器数据时,使用mysqldump命令,并指定master-data参数以及single-transaction参数以...

    Mysql修改datadir导致无法启动问题解决方法

    在这种情况下,错误信息`Can't change dir to '/mnt/hgfs/mysql_data/' (Errcode: 13)`表明MySQL无法切换到新指定的目录,错误代码13通常意味着权限不足。尽管你已经设置了正确的目录权限和文件权限,但SELinux的...

    Apache+php+mysql在windows下的安装与配置图解(最新版).doc )

    datadir=D:/mysql/data ``` - **重启MySQL服务**: 重启MySQL服务以应用配置。 #### 四、测试PHP与MySQL集成 - **创建PHP文件**: 在Apache的文档根目录下创建一个PHP文件,例如`test.php`。 - **编写PHP脚本**: ...

    php.ini-development

    data to the client. If your application's output exceeds this setting, PHP ; will send that data in chunks of roughly the size you specify. ; Turning on this setting and managing its maximum buffer ...

    Hudi_Large_Scale_Near_Real_Time_Pipelines_at_Uber

    1. **ChangeLog**:记录每个数据文件的更改历史,用于实现增量处理。 2. **Normal Table**:即传统的Hive、Spark或Presto表,作为Hudi表的底层存储。 3. **Dataset**:Hudi中的核心概念,指代一组具有特定属性的数据...

    2021-2022计算机二级等级考试试题及答案No.19777.docx

    代码`Dirl.Path = Drivel.Drive`的作用是同步更新Dirl的目录列表,使其与新选择的驱动器相对应。 2. **ADO对象**:ADO(ActiveX Data Objects)是微软的数据库访问接口。在ADO对象中,`Connection`对象用于打开和...

    Hive用户指南 Hive user guide 中文版

    - **更改列**:可以使用`ALTER TABLE table_name CHANGE COLUMN old_column new_column data_type [COMMENT column_comment]`来修改表中的列名或数据类型。 - **添加/替换列**:`ALTER TABLE table_name ADD COLUMN ...

Global site tag (gtag.js) - Google Analytics