Changing the tmp folder of mysql

前端 未结 6 994
我寻月下人不归
我寻月下人不归 2021-02-01 15:22

Our Mysql queries use temporary tables which creates temporary files in the process. Currently the files are written to /tmp. How exactly can the path of the temp folder to whic

6条回答
  •  甜味超标
    2021-02-01 16:12

    Here is an example to move the mysqld tmpdir from /tmp to /run/mysqld which already exists on Ubuntu 13.04 and is a tmpfs (memory/ram):

    sudo vim /etc/mysql/conf.d/local.cnf
    

    Add:

    [mysqld]
    tmpdir = /run/mysqld
    

    Then:

    sudo service mysql restart
    

    Verify:

    SHOW VARIABLES LIKE 'tmpdir';
    

    ==================================================================

    If you get an error on MySQL restart, you may have AppArmor enabled:

    sudo vim /etc/apparmor.d/local/usr.sbin.mysqld
    

    Add:

    # Site-specific additions and overrides for usr.sbin.mysqld.
    # For more details, please see /etc/apparmor.d/local/README.
    /run/mysqld/ r,
    /run/mysqld/** rwk,
    

    Then:

    sudo service apparmor reload 
    

    sources: http://2bits.com/articles/reduce-your-servers-resource-usage-moving-mysql-temporary-directory-ram-disk.html, https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql

提交回复
热议问题