如果你在一台 Mac 电脑上,并且使用 Homebrew 安装了 MySQL,那么这个应该对你有用。否则,您只需要替换机器上 MySQLdatadir的适当位置。
#cd to my data dir location
cd /usr/local/var/
#copy contents of local data directory to the new location
cp -r mysql/ /Volumes/myhd/mydatadir/
#temporarily move the old datadir
mv mysql mysql.local
#symlink to the new location
ln -s /Volumes/myhd/mydatadir mysql
# Create new directory for MySQL data
mkdir /new/dir/for/mysql
# Set ownership of new directory to match existing one
chown --reference=/var/lib/mysql /new/dir/for/mysql
# Set permissions on new directory to match existing one
chmod --reference=/var/lib/mysql /new/dir/for/mysql
# Stop MySQL before copying over files
service mysql stop
# Copy all files in default directory, to new one, retaining perms (-p)
cp -rp /var/lib/mysql/* /new/dir/for/mysql/
编辑 /etc/my.cnf文件,并在 [mysqld]下添加以下代码行:
datadir=/new/dir/for/mysql/
如果您正在使用 CageFS (无论是否使用 CloudLinux) ,并且希望更改 MySQL 目录,则必须将新目录添加到该文件中:
Window Key + R - will open Run
servies.msc - will open services manager
Locate MySQL80 (80 is for version 8.0, look for the one you've).
Stop it. (Right click, Stop)
步骤2 : 查找当前的 Data 目录
Goto C:\ProgramData\MySQL\MySQL Server 8.0
默认情况下,这里应该有一个名为 Data的文件夹
MySQL 在默认设置中使用(假设他们没有找到其他更好的位置) ,但是让我们检查一下。
找到 my.ini文件,应该就在那里。
在编辑器中打开它(记事本 + + 可能)。
使用 CTRL + F 来查找文件中的 datadir。
这里提到的是
当前 MySQL 用于数据目录的实际位置。
步骤3 : 用一个新的数据目录替换它。
假设您希望新的数据目录为 W: _ _ MySQL _ Data
my.ini文件中的 datadir值设置为此值。保留之前注释过的值,这样您就不必记住它了。
# Path to the database root
# datadir=C:/ProgramData/MySQL/MySQL Server 8.0/Data
datadir=W:/__MySQL_Data
# make sure you're not overwriting anything important, backup existing data
mv /usr/local/var/mysql [your preferred data directory]
ln -s [your preferred data directory] /usr/local/var/mysql
Oct 05 10:22:03 eloy-fedora-laptop mysqld[8362]: 2021-10-05 10:22:03 0 [Warning] Could not increase number of max_open_files to more than 16384 (request: 32190)
Oct 05 10:22:03 eloy-fedora-laptop mysqld[8362]: 2021-10-05 10:22:03 0 [Warning] Can't create test file /home/eloy/applications/mysql-datadir/eloy-fedora-laptop.lower->
Oct 05 10:22:03 eloy-fedora-laptop mysqld[8362]: [113B blob data]
Oct 05 10:22:03 eloy-fedora-laptop mysqld[8362]: 2021-10-05 10:22:03 0 [ERROR] Aborting
performance_schema/table_lock_waits_109.sdi
performance_schema/threads_110.sdi
performance_schema/tls_channel_stat_190.sdi
performance_schema/user_defined_fun_188.sdi
performance_schema/user_variables_b_176.sdi
performance_schema/users_144.sdi
performance_schema/variables_by_thr_183.sdi
performance_schema/variables_info_186.sdi
sys/
sys/sys_config.ibd
sent 4.44M bytes received 2.70K bytes 1.78M bytes/sec
total size is 182.35M speedup is 41.09