Modify the path of the mysql database file in linux

Source: Internet
Author: User

Mysql directly changes the storage path of data files to/etc/my. in cnf, modify the datadir and restart the service. However, I searched for more information from the Internet, most of which were changed to my. in cnf, datadir, sock, and startup script/etc/rc. the datadir in d/init/mysqld does not seem to work according to the solutions provided on the Internet. Is there a saying that hero gives me a positive explanation?

In fact, we only need to do two things: one is the mv socket and data directory. That is to say, it is to move it from the original directory to the specified location. Second, it is to modify the configuration file. If it is directly started using the command below mysql/bin, it is directly changed to my. cnf is enough, that is, you can change the ocket and data directory to your location. If you want it to automatically start the service or use the service when it is started, it is estimated that/etc/rc needs to be modified. d/init/datadir in mysqld.

There is also one:

First, let's take a look at the storage path of the current data file in the database:Copy codeThe Code is as follows: mysql> show variables like '% dir % ';
+ ---------------------------- + ------------------------------ +
| Variable_name | Value |
+ ---------------------------- + ------------------------------ +
| Basedir |/|
| Character_sets_dir |/usr/share/mysql/charsets/|
| Datadir |/data/mysql/|
| Innodb_data_home_dir |
| Innodb_log_arch_dir |
| Innodb_log_group_home_dir |./|
| Innodb_max_dirty_pages_pct | 90 |
| Slave_load_tmpdir |/tmp/|
| Tmpdir |/tmp/|
+ ---------------------------- + ------------------------------ +

If you think this path is okay, you don't have to modify it. If you are not satisfied, you can modify it.

1: service mysql stop

Close Database

2: vi/etc/rc. d/init. d/mysql

3: Change datadir =/var/lib/mysql to what you want. OK.

4: service mysql start

How to change the MySQL Data File Path

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.