首页 > 数据库 > mysql教程 > CentOS 5.8下更改MySQL的数据库目录

CentOS 5.8下更改MySQL的数据库目录

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-07 17:15:13
原创
854 人浏览过

Linux下更改MySQL的数据库目录今天要在一台双线云主机上安装 MySQL 数据库,操作系统为 CentOS 5.8,因为该机安装的时候 / 分区只

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--  ://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--  ://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  

linux

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
TP6教程问题
来自于 1970-01-01 08:00:00
0
0
0
TP5.1首发教程和独孤九剑的TP5教程区别
来自于 1970-01-01 08:00:00
0
0
0
有什么经典的symfony1.2教程
来自于 1970-01-01 08:00:00
0
0
0
求教程课件下载
来自于 1970-01-01 08:00:00
0
0
0
没有bootstrap自定义的视频教程
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板