Home > Database > Mysql Tutorial > body text

mysql modify path

PHPz
Release: 2023-05-23 09:50:07
Original
5758 people have browsed it

MySQL is a popular open source relational database management system that can run on different operating systems, including Windows, Linux and Mac systems. When using MySQL, sometimes you need to modify its default data storage path to meet different needs or restrictions. This article will introduce how to modify the MySQL data storage path under Windows and Linux systems.

1. Modify the data storage path of MySQL under Windows system

Under Windows system, the default data storage path of MySQL is: C:ProgramDataMySQLMySQL Server 5.xData. If you need to modify it to another path, you can follow the steps below:

  1. Stop the MySQL service: Open "Control Panel" → "Administrative Tools" → "Services" and find the "MySQL" service. Right click "Stop".
  2. Copy the data folder: Copy the default data storage folder C:ProgramDataMySQLMySQL Server 5.xData to a new storage path (for example, D:MySQL_data), keeping the folder name.
  3. Modify the configuration file: Open the MySQL configuration file my.ini (default path: C:ProgramDataMySQLMySQL Server 5.xmy.ini), find the [mysqld] section, and modify the datadir attribute to the new data storage path, for example datadir=D:/MySQL_data/Data.
  4. Start the MySQL service: Open "Control Panel" → "Administrative Tools" → "Services", find the "MySQL" service, right-click "Start".

After completing the above steps, MySQL will store the data in the new path without re-importing the data or resetting the program.

2. Modify the data storage path of MySQL under Linux system

Under Linux system, the default data storage path of MySQL is: /var/lib/mysql. If you need to modify it to another path, you can follow the steps below:

  1. Stop the MySQL service: Use the following command to stop the MySQL service:

$ sudo /etc/ init.d/mysql stop

  1. Copy data folder: Copy the default data storage folder /var/lib/mysql to a new storage path (such as /home/mysql_data), keep the folder name.

$ sudo cp -R /var/lib/mysql /home/mysql_data

  1. Modify the configuration file: Use a text editor to open the MySQL configuration file /etc/mysql /my.cnf, search for the [mysqld] section, and modify the datadir attribute to the new data storage path, for example, datadir=/home/mysql_data/mysql.
  2. Modify permissions: Set the correct read and write permissions for the new data storage path. Here is /home/mysql_data/mysql as an example:

$ sudo chown -R mysql:mysql /home/mysql_data/mysql
$ sudo chmod -R 755 /home/mysql_data/mysql

  1. Start the MySQL service: Use the following command to start the MySQL service:

$ sudo /etc/init.d/mysql start

After completing the above steps, MySQL will store the data in the new path without re-importing the data or resetting the program.

Summary:

The above are the steps to modify the MySQL data storage path under Windows and Linux systems. It should be noted that after modifying the data storage path, you must ensure that the path can be read and written. The permissions are correct, otherwise it may cause problems such as MySQL being unable to start normally or open the database. It is recommended that when making modifications, you first back up the data and conduct necessary testing and verification.

The above is the detailed content of mysql modify path. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!