MySQL创建数据库的时候如何指定数据文件所在的位置?

数据库服务和管理,MySQL/PostgreSQL/Oracle/Sybase 等
回复
szBobby
帖子: 58
注册时间: 2007-03-08 17:02
送出感谢: 0
接收感谢: 0

MySQL创建数据库的时候如何指定数据文件所在的位置?

#1

帖子 szBobby » 2007-04-25 21:25

我不想放在默认的路径下,想放在指定的路径,不知道如何设置

谢谢
sqlfm
帖子: 356
注册时间: 2007-02-15 6:26
送出感谢: 0
接收感谢: 1 次

#2

帖子 sqlfm » 2007-04-27 14:32

sudo gedit /etc/mysql/my.cnf

find line:

datadir = /var/lib/mysql

and update.

我没有做过。您试试看。请注意数据安全。
2007:琉璃地,旃檀林。心心作。念念是。
szBobby
帖子: 58
注册时间: 2007-03-08 17:02
送出感谢: 0
接收感谢: 0

#3

帖子 szBobby » 2007-05-04 18:01

好,我试试

谢谢
szBobby
帖子: 58
注册时间: 2007-03-08 17:02
送出感谢: 0
接收感谢: 0

#4

帖子 szBobby » 2007-05-04 21:48

sqlfm 写了:sudo gedit /etc/mysql/my.cnf

find line:

datadir = /var/lib/mysql

and update.

我没有做过。您试试看。请注意数据安全。
似乎有些问题。我修改了并重新启动之后,不能用mysql命令进入mysql,说什么sockets找不到。。。
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
zjacai
帖子: 1
注册时间: 2010-08-26 9:50
送出感谢: 0
接收感谢: 0

Re: MySQL创建数据库的时候如何指定数据文件所在的位置?

#5

帖子 zjacai » 2010-08-26 9:51

你需要将 mysql、test两个数据库目录弄到你修改的新目录下面!我在windows下也遇到过这个问题,就是这样解决的
头像
木泥黑
帖子: 1339
注册时间: 2008-10-18 12:41
送出感谢: 0
接收感谢: 0

Re: MySQL创建数据库的时候如何指定数据文件所在的位置?

#6

帖子 木泥黑 » 2010-09-15 10:59

代码: 全选

[ubuntu]change mysql data directory


一

1、 /etc/init.d/mysql stop


2、 chown mysql:mysql newdir
vim my.cnf:datadir=/var/lib/mysql ------- > datadir=/newdir

3、cp -a /var/lib/mysql/*  /newdir/*


4、vim /etc/apparmor.d/usr.sbin.mysqld
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,

/newdir/mysql/ r,
/newdir/mysql/** rwk,

5、 /etc/init.d/mysql start

二

* Open the terminal
* Stop MySQL with the command

/etc/init.d/mysql stop

* Copy the existing data directory (which is located in /var/lib/mysql) using the command

cp -R -p /var/lib/mysql /usr/new_datadir

* All you need are the data files. Delete the others with the command

       rm /usr/new_datadir


(You will get a message about not being able to delete some directories, but do not care about them)
* Edit the MySQL configuration file with the command

       vim /etc/mysql/my.cnf

* Find the entry for datadir, change the path to the new data directory.
* But there is a trick involved here. 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

       vim /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 /usr/new_datadir. Save and close the file.
* Restart the AppArmor profiles with the command

       /etc/init.d/apparmor restart

* Restart MySQL with the command

       /etc/init.d/mysql restart

* MySQL should now start without any errors and your data will be stored in the new location. See also article Linux Ubuntu move mysql database to other path in 5 minutes

回复

回到 “数据库管理”