Mysql Modify Database storage location

Source: Internet
Author: User

at work, we will encounter the need to change the database storage location, such as: the original database where the disk space is insufficient, and so on.
compiling the installed Mysql
[[Email protected] ~]# service mysqld status # First see MySQL as running state
success! MySQL Running (3794)
[[email protected] ~]# PS aux | grep mysqld | grep-v grep
# Here you can see the location of the original DataDir, there are other parameter paths
root 3543 0.0 0.1 11304 1504 pts/0 S 19:32 0:00
/bin/sh/usr/local/mysql/bin/mysqld_safe
–datadir=/usr/local/mysql/data–pid-file=/usr/local/mysql/data/localhost.pid
mysql 3794 0.0 4.3 647376 43936 pts/0 Sl 19:32 0:00
/usr/local/mysql/bin/mysqld
–basedir=/usr/local/mysql–datadir=/usr/local/mysql/data
–plugin-dir=/usr/local/mysql/lib/plugin–user=mysql
–log-error=/usr/local/mysql/data/localhost.err–pid-file=/usr/local/mysql/data/localhost.pid
–socket=/tmp/mysql.sock–port=3306
[[Email protected] ~]# service mysqld Stop # Okay, we're going to stop MySQL first .
shutting down MySQL. Success!
[[email protected] ~]# PS aux | grep mysqld | grep-v grep # no process detected
[[email protected] ~]# Mkdir/data # Create the location you want to change
[[email protected] ~]# cp-r/usr/local/mysql/data/*/data/# Copy all the contents of the original data directory to the new path
[[email protected] ~]# chown-r mysql/data/# to directory owner
[[email protected] ~]# VIM/ETC/MY.CNF # Edit configuration file
[Mysqld]
DataDir =/data# Add Database storage location
[[Email protected] ~]# service mysqld start # and start the database
starting MySQL. Success!
[[email protected] ~]# PS aux | grep mysqld | grep-v grep # can see –datadir=/data this is the new location
Root 3890 0.5 0.1 11304 1504 pts/0 S 19:52 0:00
/bin/sh/usr/local/mysql/bin/mysqld_safe–datadir=/data–pid-file=/data/localhost.pid
MySQL 4153 2.5 4.0 647376 41824 pts/0 Sl 19:52 0:00
/usr/local/mysql/bin/mysqld
–basedir=/usr/local/mysql
–datadir=/data–plugin-dir=/usr/local/mysql/lib/plugin–user=mysql–log-error=/data/localhost.err
–pid-file=/data/localhost.pid–socket=/tmp/mysql.sock–port=3306

This article is from the "System operation and maintenance website Development" blog, please be sure to keep this source http://cgc888.blog.51cto.com/3989433/1688853

Mysql Modify Database storage location

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.