Change the MySQL database storage location 5.7

Operating System: Windows 10 x64

MySQL installation package version: mysql-installer-community-5.7.17.0

Reference: MySQL 5.7 version of the installation detailed tutorial + change the database data storage path

 

By default, the database is stored in C: \ ProgramData \ MySQL \ MySQL Server 5.7 \ Data

Note: ProgramData folder is hidden, you need to check hidden items to display the folder.

 

Before the migration, we need to pause MySQL service . Right-click on this computer , select Management

 

In Computer Management , expand Services and Applications > Services , right-click on MySQL57 , select Stop

 

The C: \ ProgramData \ MySQL \ MySQL Server 5.7 \ Data copy the contents to the destination folder. For example, I copy them to E: \ ProgramData \ MySQL \ MySQL Server 5.7 \ Data

 

Open C: \ ProgramData \ MySQL \ MySQL Server 5.7 , find my.ini

 

将my.ini复制到其它盘的目录下,打开my.ini,找到datadir,datadir后面的参数,就是数据库的路径

 

修改datadir的参数,指向数据库的新路径,保存、退出。并将该文件复制到C:\ProgramData\MySQL\MySQL Server 5.7,替换原有的my.ini

 

重新启动MySQL57服务,打开MySQL 5.7 Command Line Client

查看数据库:show databases;

创建一个新的数据库:create database user;

再次查看数据库:show databases;

 

打开E:\ProgramData\MySQL\MySQL Server 5.7\Data,可以看到在该文件夹里面有一个新的文件夹user,那就是我们刚刚创建的数据库user。

 

打开C:\ProgramData\MySQL\MySQL Server 5.7\Data,这里面没有发生什么变化。

OK,设置成功了。

 

Guess you like

Origin www.cnblogs.com/Satu/p/11009636.html