Home> System Tutorial> LINUX> body text

Master explains how to modify the mariadb database storage path in Centos7.3

WBOY
Release: 2024-07-22 15:01:11
Original
742 people have browsed it

Master explains how to modify the mariadb database storage path in Centos7.3

如果你不知道当前数据库路径,只需要输入以下命令即可查看到:

回车后输入您的mariadb密码后回车

# mysql -uroot -p
Copy after login

输以下命令显示各种mariadb的路径调用情况。其中datadir项就是现存储的路径。

MariaDB [(none)]> show variables like ‘%dir%’; 退出数据库登录状态 MariaDB [(none)]> exit;
Copy after login

停止数据库

# systemctl stop mysql.server
Copy after login

新建mariadb新存储的路径文件夹

# mkdir -p /home/mysql/data
Copy after login

进入home目录

# cd /home
Copy after login

给新的路径文件夹mysql用户权限

# chown -R mysql:mysql /mysql
Copy after login

修改下面启动脚本mysql文件中的datadir路径,mysql启动脚本路径不一样,也有可能会在/usr/lib/systemd/system目录下(centos7)

# vi /etc/init.d/mysql
Copy after login

找到datadir=/var/lib/mysql修改成datadir=/home/mysql/data,如果有相同的/var/lib/mysql路径,同样修改为/home/mysql/data,

例如:

“innodb_data_home_dir”和“innodb_log_group_home_dir“
Copy after login

修改后保存并退出,在修改my.cnf中的数据存储路径

修改my.cnf文件中datadir=路径和上面修改的方法一样,修改还好以后保存并退出,然后启动mariadb服务。

# vi /etc/my.cnf # systemctl start mysql.server
Copy after login

注意:如果你有数据文件,那么就把你的贝到/home/mysql/data下,还有/var/lib/mysql下的mysql件夹也拷贝过去,其他文件就不要拷贝了,这样你新建的用户和密码都会是你以前的。如果拷贝所有文件,就会启动报错。

如果以上方式不能成功且启动报错,可以在重启失败后执行初始化数据库命令,执行数据库命令前,/home/mysql/data下必须是空的,初始化成功后再导入数据库,以下是初始化数据库的命令:

# /usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/home/mysql/data
Copy after login

再次启动就正常了

# systemctl restart mysql.server
Copy after login

初始化成功后,数据库密码是空的,执行以下命令开始设置密码

# /usr/local/mysql/bin/mysql_secure_installation
Copy after login

注意:第一个是提示你输入mysql密码,其实新安装的mysql默认是空密码,然后直接回车输入两次新密码回车,接下来全部按Y即可(基本上是删除了test测试数据库和匿名账号和删除后立刻生效(最后一个Y))。

The above is the detailed content of Master explains how to modify the mariadb database storage path in Centos7.3. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!