Linux Yum安装mysql的数据库迁移目录
Linux Yum安装mysql的数据库迁移目录
前言:因公司数据库目录存储满了,无法加空间进行更换数据目录
Warning:更换数据目录之前先问一下有么有在用,或者又没用风险之类的,如果数据库有读写或者其他操作建议晚上进行操作。
1.停用MySQL数据库
[ ~]# systemctl stop mysqld
2.查看数据现存目录迁移至所需目录
[ ~]# cat /etc/my.cnf | grep datadir datadir=/usr/local/mysql/data [ ~]# cp -ar /usr/local/mysql/ /data/
3.修改MySQL的配置文件
[ ~]# vim /etc/my.cnf #datadir=/usr/local/mysql/data #socket=/usr/local/mysql/mysql.sock datadir=/data/mysql/data socket=/data/mysql/mysql.sock
4.将socket软链接至原有目录(否则会出现启动失败的情况)
[ ~]# ln -s /data/mysql/mysql.sock /usr/local/mysql/
5.启动MySQL服务
[ ~]# systemctl start mysqld
6.查看服务状态是否正常
[ ~]# systemctl status mysqld.service ● mysqld.service - MySQL Loaded: loaded (/etc/init.d/mysql; enabled; vendor preset: disabled) Active: active (running) since 二 2020-04-07 11:55:26 CST; 1min 10s ago Process: 37229 ExecStop=/etc/init.d/mysql stop (code=exited, status=0/SUCCESS) Process: 37311 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS) Main PID: 37318 (mysqld_safe) Tasks: 28 Memory: 151.5M CGroup: /system.slice/mysqld.service ├─37318 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data --... └─37449 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data... 4月 07 11:55:25 mysql systemd[1]: Starting MySQL... 4月 07 11:55:26 mysql systemd[1]: Started MySQL.
[ ~]# ps -ef | grep mysqld mysql 37318 1 0 11:55 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/usr/local/mysql/data/mysqld.pid mysql 37449 37318 0 11:55 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/data/mysql/data/mysql.err --pid-file=/usr/local/mysql/data/mysqld.pid --socket=/data/mysql/mysql.sock root 37551 36896 0 11:56 pts/1 00:00:00 grep --color=auto mysqld
[ ~]# netstat -anpt | grep mysqld tcp6 0 0 :::3306 :::* LISTEN 37449/mysql
7.检查数据是否正常
[ ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | | wordpress | +--------------------+ 6 rows in set (0.00 sec)
相关推荐
CoderToy 2020-11-16
emmm00 2020-11-17
bianruifeng 2020-11-16
云中舞步 2020-11-12
世樹 2020-11-11
暗夜之城 2020-11-11
Coder技术文摘 2020-09-29
huacuilaifa 2020-10-29
Gexrior 2020-10-22
tufeiax 2020-09-03
疯狂老司机 2020-09-08
王艺强 2020-11-17
aydh 2020-11-12
zry 2020-11-11
URML 2020-11-11
spurity 2020-11-10
yifangs 2020-10-13
Andrea0 2020-09-18
Ida 2020-09-16
ltd00 2020-09-12
xjd0 2020-09-10