Basic knowledge about MySQL in Linux

Source: Internet
Author: User

A basic example

Linux MySQL changes the directory location of the MySQL database

The default data file storage directory of MySQL is/var/lib/mysql. To move the directory to/home/data, perform the following steps:

1. Create a data directory under the home Directory

Cd/homemkdir data

2. Stop the MySQL service process:

Mysqladmin-u root-p shutdown

3. Move the entire/var/lib/mysql directory to/home/data

Mv/var/lib/mysql/home/data/

In this way, the MySQL data file is moved to/home/data/mysql.

4. Find the my. cnf configuration file.

If my. the cnf configuration file (www.avnads.cn) can be found under/usr/share/mysql *. copy one of the cnf files to/etc/and change it to my. cnf. The command is as follows:

[Root @ test1 mysql] # cp/usr/share/mysql/my-medium.cnf/etc/my. cnf

5. Edit the MySQL configuration file/etc/my. cnf.

To ensure that MySQL works properly, you must specify the location where the mysql. sock file is generated. Change socket =/var/lib/mysql. sock to/home/mysql. sock. The procedure is as follows:

Vi my. cnf (use vi tool to edit my. cnf file, find The following data to modify) # The MySQL server [mysqld] port = 3306 # socket =/var/lib/mysql. sock (original content, to make it more secure to use "#" to comment out this line) socket =/home/data/mysql. sock (previous line)

6. Modify the MySQL STARTUP script/etc/init. d/mysql

Finally, you need to modify the MySQL STARTUP script/etc/init. d/mysql: change the path on the Right of datadir =/var/lib/mysql to your actual storage path: home/data/mysql.

[Root @ test1 etc] # vi/etc/init. d/mysql # datadir =/var/lib/mysql (comment this line) datadir =/home/data/mysql (previous line)

7. Restart the MySQL service.

/Etc/init. d/mysql start

Or use the reboot command to restart Linux.

If it works properly, it will succeed. Otherwise, check again against the previous seven steps. Pay attention to the owner and permissions of the directory.

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.