博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux下更改MySQL的数据库目录
阅读量:2442 次
发布时间:2019-05-10

本文共 3852 字,大约阅读时间需要 12 分钟。

Linux下更改MySQL的数据库目录

今天要在一台双线云主机上安装 MySQL 数据库,操作系统为 CentOS 5.8,因为该机安装的时候 / 分区只有20G,还有一个 300G 的扩展磁盘分区挂载在 /disk ,因此需要将 MySQL 的数据库目录设置在 /disk/mysql ,下面是具体操作步骤。

 

操作系统:CentOS 5.8

MySQL 版本:5.5.25

目标:更改MySQL数据库目录

源目录:/var/lib/mysql   (系统默认目录)

目标目录:/disk/mysql

 

1. 安装 MySQL 数据库软件

如果已经有,则跳过。MySQL 最新版本为 5.5.25

 

-bash-3.2# rpm -qa | grep MySQL

-bash-3.2# mkdir -p setup

-bash-3.2# cd setup/
-bash-3.2# wget "http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.25-1.rhel5.i386.rpm/from/http://mirror.csclub.uwaterloo.ca/mysql/"
--2012-06-06 16:48:29--  http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.25-1.rhel5.i386.rpm/from/http://mirror.csclub.uwaterloo.ca/mysql/
2012-06-06 16:49:52 (216 KB/s) - `MySQL-client-5.5.25-1.rhel5.i386.rpm' saved [17860149/17860149]
-bash-3.2# wget "http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.25-1.rhel5.i386.rpm/from/http://mysql.mirror.iweb.ca/"
--2012-06-06 16:50:01--  http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.25-1.rhel5.i386.rpm/from/http://mysql.mirror.iweb.ca/

 

2012-06-06 16:57:11 (132 KB/s) - `MySQL-server-5.5.25-1.rhel5.i386.rpm' saved [54564826/54564826]

 

-bash-3.2# rpm -ivh MySQL-server-5.5.25-1.rhel5.i386.rpm MySQL-client-5.5.25-1.rhel5.i386.rpm

error: Failed dependencies:
        libaio.so.1 is needed by MySQL-server-5.5.25-1.rhel5.i386
        libaio.so.1(LIBAIO_0.1) is needed by MySQL-server-5.5.25-1.rhel5.i386
        libaio.so.1(LIBAIO_0.4) is needed by MySQL-server-5.5.25-1.rhel5.i386
-bash-3.2# yum install -y libaio

Installed:

  libaio.i386 0:0.3.106-5                                                                                                                                             
Complete!
-bash-3.2# rpm -ivh MySQL-server-5.5.25-1.rhel5.i386.rpm MySQL-client-5.5.25-1.rhel5.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [ 50%]
   2:MySQL-server           ########################################### [100%]
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
-bash-3.2#

 

2. ·停止 MySQL 服务器

如果MySQL服务器正在运行,应该先将其停止。

我因为刚安装好,所以并未运行。

-bash-3.2# service mysql stop

 ERROR! MySQL server PID file could not be found!
-bash-3.2# service mysql status
 ERROR! MySQL is not running

 

 

3. 移动数据库目录到目标位置

-bash-3.2# mv /var/lib/mysql /disk

 

-bash-3.2# ls /disk/

logs  lost+found  mysql
-bash-3.2#

 

4. 创建或修改配置文件 /etc/my.cnf

 

[client]

default-character-set=gbk
socket=/disk/mysql/mysql.sock
[mysqld]
character-set-server=gbk
socket=/disk/mysql/mysql.sock

 

 

5. 修改 MySQL 启动脚本 /etc/init.d/mysql

 

原内容

# If you change base dir, you must also change datadir. These may get

# overwritten by settings in the MySQL configuration files.
basedir=
datadir=

 

 

修改后的内容

# If you change base dir, you must also change datadir. These may get

# overwritten by settings in the MySQL configuration files.
basedir=
datadir=/disk/mysql

 

6. 启动 MySQL 服务器

-bash-3.2# service mysql start 

Starting MySQL.. SUCCESS!
-bash-3.2# service mysql status
 SUCCESS! MySQL running (4874)
-bash-3.2#

 

7. 测试 MySQL 访问是否正常

-bash-3.2# mysql -p

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 188
Server version: 5.5.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

 

O.K.!

 

本文链接:

END.

 

 

 

 

 

转载地址:http://kmnqb.baihongyu.com/

你可能感兴趣的文章
每个设计专业学生都需要知道的8件事
查看>>
微软云 az-100_新的Microsoft AZ-900考试:参加理由–为什么要准备考试
查看>>
企业为什么需要it服务?_为什么要考虑为您的企业提供IT支持服务?
查看>>
Django博客教程–创建一个简单的博客
查看>>
操作系统的主要类型_操作系统类型
查看>>
编程和编码的区别_安全编程和编码提示
查看>>
实用的小应用_使您的新应用更安全的实用提示
查看>>
小学生c语言编程入门教程_学生编程语言
查看>>
linux ops_使用OPS在现有Linux应用程序中运行Unikernels
查看>>
icloud unlock_iCloud Unlock 2019的7大替代解决方案
查看>>
os和操作系统_操作系统(OS)中的抛出
查看>>
android mvp示例_Android深层链接示例
查看>>
Android RSS阅读器教程
查看>>
SkySilk –托管云服务提供商
查看>>
什么是虚拟主机? 为什么我需要它?
查看>>
django安装 mac_如何在Windows / Linux / Mac上安装Django
查看>>
kettle 逐行读取文件_C程序逐行读取文件
查看>>
数据结构 线性 非线性_线性和非线性数据结构之间的区别
查看>>
精益开发原则_了解精益发展的核心原则
查看>>
python speech_使用Google Speech API进行Python语音识别
查看>>