The storage location of the mysql database is stored in the C directory by default. It is usually stored in the db in linux, but we can modify the storage location of the mysql database files at any time, next, I will introduce the modification methods in linux, freebsd, and windows.
When mysql is installed on the FreeBSD host, the database files are stored in/var/db/mysql. The default storage location on the Linux host is/var/lib/mysql.
If you want to change the storage location of mysql data files:
FreeBSD:
#/Usr/local/etc/rc. d/mysql-server stop (stop mysql)
# Mkdir/other/db (create a new data file directory or move it directly)
# Mv/var/db/mysql/other/db (move data files)
# Ln-s/other/db/mysql/var/db/mysql (create a soft link to the data file)
#/Usr/local/etc/rc. d/mysql-server start (start mysql)
In Linux:
(You can directly operate mysql without stopping mysql after testing in linux. However, if the database is frequently updated or stopped first, the stop method will not be introduced here !)
# Mkdir/data/database (create a new data file directory or move it directly)
# Mv/var/lib/mysql/data/database/(move data files)
# Ln-s/data/database/mysql/var/lib/mysql (create a soft link to the data file)
If the user you operate is not mysql, such as the root user, mysql may not have the read permission for the newly created data folder, as well as chown, or chgrp or chmod!
How to modify windows
1. query the data file storage location
Mysql> show variables like 'datadir'
->;
+ --------------- + ------------------- +
| Variable_name | Value |
+ --------------- + ------------------- +
| Datadir | D:/MySql5.0/data/|
+ --------------- + ------------------- +
1 row in set (0.00 sec)
Mysql> show variables like 'datadir'
->;
+ --------------- + ------------------- +
| Variable_name | Value |
+ --------------- + ------------------- +
| Datadir | D:/MySql5.0/data/|
+ --------------- + ------------------- +
1 row in set (0.00 sec)
2. Stop the mysql database and use the net command to stop the address service.
C:/Documents and Settings/Administrator> net stop mysql
The MySQL service is stopping.
The MySQL service has been stopped successfully.
C:/Documents and Settings/Administrator> net stop mysql
The MySQL service is stopping.
The MySQL service has been stopped successfully.
Of course, you can also view the my. ini file under the Mysql directory.
3. Modify the my. ini folder
# Path to the database root
Datadir = "D:/MySql5.0/data"
4. Start the service OK
C:/Documents and Settings/Administrator> net start mysql
MySQL service is starting.
The MySQL service has been started successfully.