How to modify the storage location of mysql Data Files

Source: Internet
Author: User
Tags net command

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.