Mysql日志文件默认路径的修改方法(Mysql binlog relocate)

Moving MySQL data and logs on Ubuntu to a new location the hard way


There's lots of information online on how to move MySQL data and logs to a new location but I had to use a combination of several guides in order to get it fully working. This is a reference for me if I ever need to do it again or for anyone else that may find it useful.
Also, if I ever have to do it again, I would definitely choose a much simpler way of just binding the new directory to the default one in /etc/fstab. Something like:
echo "/new/path/for/mysql/data /var/lib/mysql none bind" | sudo tee -a /etc/fstab
as it eliminates all problems with apparmor and having to manually update binary log index files. This way you don't need to do steps 3 through 6, though you have to move the data and not copy in this case.

Step 1: stop mysql

sudo service mysql stop

Step 2: copy/move the data

sudo cp -rp /var/lib/mysql/ /new/path/for/mysql/data/
sudo cp -rp /var/log/mysql/ /new/path/for/mysql/logs/

Step 3: edit mysql config replacing old paths with new ones

sudo nano /etc/mysql/my.cnf

Step 4: edit apparmor config for mysql replacing old paths with new ones

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

Step 5: edit mysql binary log index file replacing old paths with new ones

sudo nano /new/path/for/mysql/logs/mysql-bin.index

Step 6: restart apparmor to make sure that it picks up the new config

sudo service apparmor restart

Step 7: finally, start mysql and pray that everything works

sudo service mysql start

亲测有效

转载地址: https://ivan-site.com/2011/01/moving-mysql-data-and-logs-on-ubuntu-to-a-new-location-the-hard-way/


方法2

利用 Mysql Utilities -- mysqlbinlogmove

Usage.eg

  1. Stop the running MySQL server.
  2. Start the mysqlbinlogmove utility and specify the source directory of the binary log files and the target directory.
    shell> mysqlbinlogmove --binlog-dir=/var/lib/mysql \
           /mysql/server/binlogs
    #
    # Moving bin-log files...
    # - server-bin.000001
    # - server-bin.000002
    # - server-bin.000003
    # - server-bin.000004
    # - server-bin.000005
    # - server-bin.000006
    # - server-bin.000007
    # - server-bin.000008
    # - server-bin.000009
    # - server-bin.000010
    # - server-bin.000011
    #
    #...done.
    #
    
  3. Restart the MySQL server with the new value for the --log-bin option: --log-bin=/mysql/server/binlogs/server-bin.

你可能感兴趣的:(LUG,Palest,Ink)